Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

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.

NoteNote:

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);
// Create a resolver with default credentials.
XmlUrlResolver* resolver = new XmlUrlResolver();
resolver->Credentials = System::Net::CredentialCache::DefaultCredentials;

// Create the XmlReader object.
XmlReader* reader = XmlReader::Create(S"http://ServerName/data/books.xml", 0, resolver, 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.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft