XmlResolver Class
Resolves external XML resources named by a Uniform Resource Identifier (URI).
Namespace: System.Xml
Assembly: System.Xml (in System.Xml.dll)
The XmlResolver type exposes the following members.
| Name | Description | |
|---|---|---|
![]() ![]() | Credentials | When overridden in a derived class, sets the credentials used to authenticate Web requests. |
![]() ![]() | NameTable | Obsolete. Obsolete |
| Name | Description | |
|---|---|---|
![]() ![]() | Equals(Object) | Determines whether the specified object is equal to the current object. (Inherited from Object.) |
![]() ![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() ![]() | GetEntity | When overridden in a derived class, maps a URI to an object containing the actual resource. |
![]() | GetEntityAsync | Asynchronously maps a URI to an object containing the actual resource. |
![]() ![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() ![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() ![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() ![]() | ResolveUri | When overridden in a derived class, resolves the absolute URI from the base and relative URIs. |
![]() | SupportsType | Adds the ability for the resolver to return other types than just Stream. |
![]() ![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
XmlResolver is used to resolve external XML resources, such as entities, document type definitions (DTDs), or schemas. It is also used to process include and import elements found in Extensible StyleSheet Language (XSL) style sheets or XML Schema definition language (XSD) schemas.
XmlUrlResolver is a concrete implementation of XmlResolver and is the default resolver for all classes in the System.Xml namespace. You can also create your own resolver.
Security Considerations
Consider the following items when working with the XmlResolver class.
XmlResolver objects can contain sensitive information such as user credentials. You should be careful when caching XmlResolver objects and should not pass the XmlResolver object to an untrusted component.
If you are designing a class property that uses the XmlResolver class, the property should be defined as a write-only property. The property can be used to specify the XmlResolver to use, but it cannot be used to return an XmlResolver object.
If your application accepts XmlResolver objects from untrusted code, you cannot assume that the URI passed into the GetEntity method will be the same as that returned by the ResolveUri method. Classes derived from the XmlResolver class can override the GetEntity method and return data that is different than what was contained in the original URI.
Your application can mitigate memory Denial of Service threats to the GetEntity method by implementing a wrapping implemented IStream that limits the number of bytes read. This helps to guard against situations where malicious code attempts to pass an infinite stream of bytes to the GetEntity method.
The following example creates an XmlUrlResolver with default credentials. A XmlReader is used to read and display the resulting data stream.
using System; using System.Xml; using System.IO; class Example { static void Main() { // Create an XmlUrlResolver with default credentials. XmlUrlResolver resolver = new XmlUrlResolver(); resolver.Credentials = System.Net.CredentialCache.DefaultCredentials; // Point the resolver at the desired resource and resolve as a stream. Uri baseUri = new Uri("http://serverName/"); Uri fulluri = resolver.ResolveUri(baseUri, "fileName.xml"); Stream s = (Stream)resolver.GetEntity(fulluri, null, typeof(Stream)); // Create the reader with the resolved stream and display the data. XmlReader reader = XmlReader.Create(s); while (reader.Read()) { Console.WriteLine(reader.ReadOuterXml()); } } }
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.



