Accessing External Resources for the XmlReader

Accessing External Resources for the XmlReader

The XmlResolver class is used to locate and access any resources required by the XmlReader object.

The XmlResolver can be used to do the following:

  • Locate and open the XML instance document.

  • Locate and open any external resources referenced by the XML instance document. This can include entities, a document type definition, schemas, and so on.

  • If the resource is stored on a system that requires authentication, the XmlResolver.Credentials property can be used to specify the necessary credentials.

You specify the XmlResolver to use by setting the XmlReaderSettings.XmlResolver property and passing the XmlReaderSettings object to the Create method.


If an XmlResolver is not specified, the created reader uses a default XmlUrlResolver with no user credentials.

The following code creates an XmlReader instance that uses an XmlUrlResolver with default credentials.

// Create a resolver with default credentials.
XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials = System.Net.CredentialCache.DefaultCredentials;

// Set the reader settings object to use the resolver.
settings.XmlResolver = resolver;

// Create the XmlReader object.
XmlReader reader = XmlReader.Create("http://ServerName/data/books.xml", settings);

The System.Xml namespace includes two concrete implementations of the XmlResolver class.

For additional information, see Resolve External XML Resources Named by a URI.

© 2016 Microsoft