Muokkaa

Jaa


XmlResolver Class

Definition

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

public ref class XmlResolver abstract
public abstract class XmlResolver
type XmlResolver = class
Public MustInherit Class XmlResolver
Inheritance
XmlResolver
Derived

Examples

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());
        }
    }
}
Imports System.Xml
Imports System.IO

Module Module1

    Sub Main()
        ' Create an XmlUrlResolver with default credentials.
        Dim resolver As New XmlUrlResolver()
        resolver.Credentials = System.Net.CredentialCache.DefaultCredentials

        ' Point the resolver at the desired resource and resolve as a stream.
        Dim baseUri As New Uri("http://serverName/")
        Dim fulluri As Uri = resolver.ResolveUri(baseUri, "fileName.xml")
        Dim s As Stream = CType(resolver.GetEntity(fulluri, Nothing, GetType(Stream)), Stream)

        ' Create the reader with the resolved stream and display the data.
        Dim reader As XmlReader = XmlReader.Create(s)
        While reader.Read()
            Console.WriteLine(reader.ReadOuterXml())
        End While
    End Sub
End Module

Remarks

For more information about this API, see Supplemental API remarks for XmlResolver.

Constructors

XmlResolver()

Initializes a new instance of the XmlResolver class.

Properties

Credentials

When overridden in a derived class, sets the credentials used to authenticate web requests.

FileSystemResolver

Gets an XML resolver that resolves only file system URIs.

ThrowingResolver

Gets an XML resolver that forbids entity resolution.

Methods

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEntity(Uri, String, Type)

When overridden in a derived class, maps a URI to an object that contains the actual resource.

GetEntityAsync(Uri, String, Type)

Asynchronously maps a URI to an object that contains the actual resource.

GetHashCode()

Serves as the default hash function.

(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(Uri, String)

When overridden in a derived class, resolves the absolute URI from the base and relative URIs.

SupportsType(Uri, Type)

Enables the resolver to return types other than Stream.

ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to

See also