Resolving Resources Using the XmlResolver

The XmlValidatingReader class uses XmlResolver to resolve external DTDs, entities, and schemas. In order to resolve these external resources, the XmlResolver property in XmlValidatingReader must be set. The following example shows how to set the resolver to resolve an external DTD resource used by XmlValidatingReader.

dim vreader as New
dim resolver As new XmlUrlResolver()
vreader.XmlResolver = resolver
while vreader.Read
    . . . 
End While
XmlValidatingReader vreader =           
vreader.XmlResolver = new XmlUrlResolver();
       . . . 

To resolve a DTD, XmlValidatingReader calls the GetEntity method to get a stream representation of the entity. If the URI of the DTD is a relative URI, then XmlValidatingReader calls the ResolveUri method and returns an absolute URI for the given relativeUri and baseUri. If XmlResolver does not know how to resolve the given URI, then it returns a null reference.

Additionally, if security settings are required to access the external resource, then the Credentials property can be set accordingly. The Credentials property implements the interface ICredentials. This property enables the user to set authentication settings for URIs. For more information on supplying credentials, see Supplying Authentication Credentials to XmlResolver when Reading from a File.

The GetEntity method in the XmlUrlResolver uses the information in the Credentials property as appropriate to gain access to the resource. There is no get accessor to this property for security reasons. When overwriting XmlResolver, GetEntity is the method that utilizes the credential information in the Credentials property.

If you do not provide an XmlResolver for the XmlValidatingReader to use, then a default XmlUrlResolver is created and null credentials are used.

Resolving all other XML resources is very similar to resolving DTDs. XmlResolver needs to know only how to negotiate the connection with the external resource, and return a Stream representation of the content. It is the object that is making the call to XmlResolver that has the task of interpreting the stream.

See Also

Resolve External XML Resources Named by a URI | Supplying Authentication Credentials to XmlResolver when Reading from a File | Creating a Custom Resolver