System.Xml.XmlResolver Class

Assembly: System.Xml.dll
Namespace: System.Xml
Summary
Resolves external XML resources named by a URI.
C# Syntax:
public abstract class XmlResolver
Remarks
XmlResolver is used to resolve external XML resources such as entities, 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.

XmlUrlResolver is the default resolver for all classes in the System.Xml namespace. However, you can also create your own resolver. For more information on implementing your own resolver, see the conceptual topic at MSDN: creatingcustomresolver.

See also:
System.Xml Namespace

System.Xml.XmlResolver Member List:

Public Properties
Credentials Write-only

When overridden in a derived class, sets the credentials used to authenticate Web requests.
Public Methods
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetEntity When overridden in a derived class, maps a URI to an object containing the actual resource.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
ResolveUri When overridden in a derived class, resolves the absolute URI from the base and relative URIs.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Protected Constructors
ctor #1 Default constructor. This constructor is called by derived class constructors to initialize state in this type.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Xml.XmlResolver Member Details

ctor #1
Summary:
Default constructor. This constructor is called by derived class constructors to initialize state in this type.
C# Syntax:
protected XmlResolver();

Return to top


Property: Credentials (write-only)
Summary
When overridden in a derived class, sets the credentials used to authenticate Web requests.
C# Syntax:
ICredentials Credentials {set;}
Remarks
If the virtual directory is configured to allow anonymous access, this property does not need to be set. Otherwise, the credentials of the user must be supplied. If credentials are needed but not supplied, the resolver uses default credentials (CredentialCache.DefaultCredentials).

The following C# code sets credentials for the virtual directory "http://localhost/bookstore/inventory.xml"

              XmlTextReader reader = new XmlTextReader("http://localhost/bookstore/inventory.xml");
              NetworkCredential nc = new NetWorkCredential("username", "password", "domain");
              XmlUrlResolver resolver = new XmlUrlResolver();
              resolver.Credentials = nc;
              reader.XmlResolver= resolver;
                 
            

Different credentials can be associated with different URIs, and added to a credential cache. The credentials can then be used to check authentication for different URIs regardless of the original source of the XML.

              NetworkCredential myCred = new NetworkCredential("username","password","domain"); 
              CredentialCache myCache = new CredentialCache(); 
              myCache.Add(new Uri("http://www.contoso.com/"), "Basic", myCred); 
              myCache.Add(new Uri("http://app.contoso.com/"), "Basic", myCred);
              XmlUrlResolver resolver = new XmlUrlResolver();
              resolver.Credentials = myCache;
              reader.XmlResolver = resolver;
                 
            
Example
See XmlUrlResolver.Credentials (in the XmlUrlResolver class) for an example using this property.

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~XmlResolver();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetEntity(
   Uri absoluteUri,
   string role,
   Type ofObjectToReturn
)
Summary
When overridden in a derived class, maps a URI to an object containing the actual resource.
C# Syntax:
public abstract object GetEntity(
   Uri absoluteUri,
   string role,
   Type ofObjectToReturn
);
Parameters:

absoluteUri

The URI returned from XmlResolver.ResolveUri

role

The current version does not use this parameter when resolving URIs. This is provided for future extensibility purposes. For example, this can be mapped to the xlink:role and used as an implementation specific argument in other scenarios.

ofObjectToReturn

The type of object to return. The current version only returns System.IO.Stream objects.

Return Value:
A System.IO.Stream object or null if a type other than stream is specified.
Exceptions
Exception Type Condition
XmlException There is a runtime error (for example, an interrupted server connection).
UriFormatException The specified URI is not an absolute URI.
Remarks
This method is used when the caller wants to map a given URI into the object containing the actual resource that the URI represents. The type of object returned is negotiable however the implementation must always support System.IO.Stream.
Example
See XmlUrlResolver.GetEntity (in the XmlUrlResolver class) for an example using this method.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: ResolveUri(
   Uri baseUri,
   string relativeUri
)
Summary
When overridden in a derived class, resolves the absolute URI from the base and relative URIs.
C# Syntax:
public abstract Uri ResolveUri(
   Uri baseUri,
   string relativeUri
);
Parameters:

baseUri

The base URI used to resolve the relative URI

relativeUri

The URI to resolve. The URI can be absolute or relative. If absolute, this value effectively replaces the baseUri value. If relative, it combines with the baseUri to make an absolute URI. The URI to resolve. The URI can be absolute or relative. If absolute, this value effectively replaces the baseUri value. If relative, it combines with the baseUri to make an absolute URI.

Return Value:
The absolute URI or null if the relative URI can not be resolved.
Exceptions
Exception Type Condition
UriFormatException The supplied URIs are not absolute.
Remarks
The absolute URI may be used as the base URI for any subsequent requests for entities that are relative to this URI.
Example
See XmlUrlResolver.ResolveUri (in the XmlUrlResolver class) for an example using this method.

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.