Freigeben über


XmlResolver Class

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Resolves external XML resources named by a Uniform Resource Identifier (URI).

Inheritance Hierarchy

System.Object
  System.Xml.XmlResolver
    System.Xml.Resolvers.XmlPreloadedResolver
    System.Xml.XmlXapResolver

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)

Syntax

'Declaration
Public MustInherit Class XmlResolver
public abstract class XmlResolver

The XmlResolver type exposes the following members.

Constructors

  Name Description
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 XmlResolver Initializes a new instance of the XmlResolver class.

Top

Methods

  Name Description
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 Finalize Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetEntity When overridden in a derived class, maps a URI to an object containing the actual resource.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetType Gets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 ResolveUri When overridden in a derived class, resolves the absolute URI from the base and relative URIs.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 SupportsType This method adds the ability for the resolver to return other types than just Stream.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Remarks

XmlResolver is used to resolve external XML resources, such as entities or document type definitions (DTDs).

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.

Examples

The following example preloads the DTDs and entities defined in XHTML 1.0 by setting Xhtml10 on the XmlPreloadedResolver. In this example, the XHTMLPage.html file is a part of the application's XAP package; therefore, we have to pass a fallback resolver to the constructor of the XmlPreloadedResolver.

Dim settings As XmlReaderSettings = New XmlReaderSettings()
settings.XmlResolver = New XmlPreloadedResolver(New XmlXapResolver(), XmlKnownDtds.Xhtml10)
Using reader As XmlReader = XmlReader.Create("HTMLPage.html", settings)
    Dim document As XDocument = XDocument.Load(reader)
    OutputTextBlock.Text = document.ToString()
End Using

XmlReaderSettings settings = new XmlReaderSettings();
settings.DtdProcessing = DtdProcessing.Parse;
settings.XmlResolver =
    new XmlPreloadedResolver(new XmlXapResolver(),
        XmlKnownDtds.Xhtml10);

using (XmlReader reader = XmlReader.Create("HTMLPage.html", settings))
{
XDocument document = XDocument.Load(reader);
OutputTextBlock.Text = document.ToString();
}

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.