XmlPreloadedResolver Class

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

The XmlPreloadedResolver type is used to prepopulate the cache with DTDs or XML streams.

Inheritance Hierarchy

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

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

Syntax

'Declaration
Public Class XmlPreloadedResolver _
    Inherits XmlResolver
public class XmlPreloadedResolver : XmlResolver

The XmlPreloadedResolver type exposes the following members.

Constructors

  Name Description
Public method XmlPreloadedResolver() Initializes a new instance of the XmlPreloadedResolver class.
Public method XmlPreloadedResolver(XmlKnownDtds) Initializes a new instance of the XmlPreloadedResolver class with the specified preloaded well-known DTDs.
Public method XmlPreloadedResolver(XmlResolver) Initializes a new instance of the XmlPreloadedResolver class with the specified fallback resolver.
Public method XmlPreloadedResolver(XmlResolver, XmlKnownDtds) Initializes a new instance of the XmlPreloadedResolver class with the specified fallback resolver and preloaded well-known DTDs.
Public method XmlPreloadedResolver(XmlResolver, XmlKnownDtds, IEqualityComparer<Uri>) Initializes a new instance of the XmlPreloadedResolver class with the specified fallback resolver, preloaded well-known DTDs and URI equality comparer.

Top

Properties

  Name Description
Public property PreloadedUris Gets a collection of preloaded URIs.

Top

Methods

  Name Description
Public method Add(Uri, array<Byte[]) Adds a Stream, byte array, or string with preloaded data to the XmlPreloadedResolver store and maps it to a URI. If the store already contains a mapping for the same URI, the existing mapping is overridden.
Public method Add(Uri, Stream) Adds a Stream, byte array, or string with preloaded data to the XmlPreloadedResolver store and maps it to a URI. If the store already contains a mapping for the same URI, the existing mapping is overridden.
Public method Add(Uri, String) Adds a Stream, byte array, or string with preloaded data to the XmlPreloadedResolver store and maps it to a URI. If the store already contains a mapping for the same URI, the existing mapping is overridden.
Public method Add(Uri, array<Byte[], Int32, Int32) Adds a Stream, byte array, or string with preloaded data to the XmlPreloadedResolver store and maps it to a URI. If the store already contains a mapping for the same URI, the existing mapping is overridden.
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method 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 method GetEntity Maps a URI to an object that contains the actual resource. (Overrides XmlResolver.GetEntity(Uri, String, Type).)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method Remove Removes the data corresponding to the URI from the XmlPreloadedResolver.
Public method ResolveUri Resolves the absolute URI from the base and relative URIs. (Overrides XmlResolver.ResolveUri(Uri, String).)
Public method SupportsType Returns true if the resolver’s GetEntity method can resolve the provided URI into an instance of the provided Type. (Overrides XmlResolver.SupportsType(Uri, Type).)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Remarks

The XmlPreloadedResolver type is used as a resolver when automatic calls to the network are not desired or are not possible. For example, this type can be used for loading cached external DTDs. Or, you might use XmlPreloadedResolver to preload well-known DTDs that are defined in XHTML 1.0. Preloading well-known DTDs does not invoke any network connections, because these DTDs are already embedded in the System.Xml.Utils assembly. Currently, XmlPreloadedResolver includes the DTDs that are defined in XHTML 1.0 and RSS 0.91.

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

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.