Accessing External Resources for the XmlReader
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.
// 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);
XmlUrlResolver – Resolves using the file:// and http:// protocols. This is the default resolver used.
For additional information, see Resolve External XML Resources Named by a URI.