public class XmlUrlResolver : XmlResolver
Object
XmlResolver
XmlUrlResolver
System.Xml
XML
Resolves external XML resources named by a URI.
This class is used to resolve external XML resources such as entities, document type definitions (DTDs), or schemas. It is also used to process include and import elements found in Extensible StyleSheet Language (XSL) stylesheets or XML Schema Definition language (XSD) schemas.This class implements the XmlResolver class.
System.Xml Namespace
XmlUrlResolver Constructors
XmlUrlResolver Methods
XmlUrlResolver.GetEntity Method
XmlUrlResolver.ResolveUri Method
XmlUrlResolver Properties
public XmlUrlResolver();
Constructs and initializes a new instance of the XmlUrlResolver class.
System.Xml.XmlUrlResolver Class, System.Xml Namespace
public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn);
Maps a URI to an object containing the actual resource that the URI represents.
- absoluteUri
- The Uri returned from System.Xml.XmlUrlResolver.ResolveUri(System.Uri,System.String).
- role
- This parameter is not used.
- ofObjectToReturn
null
ortypeof
(Stream).
A Stream containing the resource, ornull
if ofObjectToReturn isnull
.
Exception Type Condition NullReferenceException absoluteUri is null
.XmlException ofObjectToReturn is not null
ortypeof
(Stream).
[Note: This method overrides System.Xml.XmlResolver.GetEntity(System.Uri,System.String,System.Type).]
System.Xml.XmlUrlResolver Class, System.Xml Namespace
public override Uri ResolveUri(Uri baseUri, string relativeUri);
Resolves the absolute URI from the base and relative URIs.
- baseUri
- The Uri specifying the base URI used to resolve relativeURI.
- relativeUri
- A String specifying the URI to resolve. The URI can be absolute or relative.
A Uri containing the absolute URI, ornull
if relativeUri can not be resolved.
Exception Type Condition ArgumentException relativeUri is null
.
If relativeURI isnull
, it is set to System.String.Empty.[Note: The absolute URI can be used as the base URI for any subsequent requests for entities that are relative to this URI.
This method overrides System.Xml.XmlResolver.ResolveUri(System.Uri,System.String).
]
System.Xml.XmlUrlResolver Class, System.Xml Namespace
public override ICredentials Credentials { set; }
Sets the credentials used to authenticate Web requests.
A ICredentials instance containing the credentials.
This property is write-only.If the virtual directory is configured to allow anonymous access, credentials are not needed and this property does not need to be set.
[Note: This property overrides System.Xml.XmlResolver.Credentials.
]
The following example sets credentials for the virtual directory "http://localhost/bookstore/inventory.xml". There is no output from this example.
using System; using System.Net; using System.Xml; public class App { public static void Main() { XmlTextReader xtReader = new XmlTextReader("http://localhost/" + "bookstore/inventory.xml"); NetworkCredential netCredential = new NetworkCredential("username", "password", "domain"); XmlUrlResolver xResolver = new XmlUrlResolver(); xResolver.Credentials = netCredential; xtReader.XmlResolver= xResolver; } }The following example associates different credentials with different URIs and adds the credentials to a credential cache. The credentials can then be used to check authentication for different URIs regardless of the original source of the XML. There is no output from this example.
using System; using System.Net; using System.Xml; public class App { public static void Main() { XmlTextReader xtReader = new XmlTextReader("http://localhost/" + "bookstore/inventory.xml"); NetworkCredential netCredential1 = new NetworkCredential("username1", "password1", "domain1"); NetworkCredential netCredential2 = new NetworkCredential("username2", "password2", "domain2"); CredentialCache credCache = new CredentialCache(); credCache.Add( new Uri("http://www.contoso.com/"), "Basic", netCredential1); credCache.Add( new Uri("http://app.contoso.com/"), "Basic", netCredential2); XmlUrlResolver xResolver = new XmlUrlResolver(); xResolver.Credentials = credCache; xtReader.XmlResolver= xResolver; } }
System.Xml.XmlUrlResolver Class, System.Xml Namespace