System.Xml.XmlUrlResolver Class

public class XmlUrlResolver : XmlResolver

Base Types

Object
  XmlResolver
    XmlUrlResolver

Assembly

System.Xml

Library

XML

Summary

Resolves external XML resources named by a URI.

Description

This class 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) stylesheets or XML Schema Definition language (XSD) schemas.

This class implements the XmlResolver class.

See Also

System.Xml Namespace

Members

XmlUrlResolver Constructors

XmlUrlResolver Constructor

XmlUrlResolver Methods

XmlUrlResolver.GetEntity Method
XmlUrlResolver.ResolveUri Method

XmlUrlResolver Properties

XmlUrlResolver.Credentials Property


XmlUrlResolver Constructor

public XmlUrlResolver();

Summary

Constructs and initializes a new instance of the XmlUrlResolver class.

See Also

System.Xml.XmlUrlResolver Class, System.Xml Namespace

XmlUrlResolver.GetEntity Method

public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn);

Summary

Maps a URI to an object containing the actual resource that the URI represents.

Parameters

absoluteUri
The Uri returned from System.Xml.XmlUrlResolver.ResolveUri(System.Uri,System.String).
role
This parameter is not used.
ofObjectToReturn
null or typeof (Stream).

Return Value

A Stream containing the resource, or null if ofObjectToReturn is null .

Exceptions

Exception TypeCondition
NullReferenceExceptionabsoluteUri is null .
XmlExceptionofObjectToReturn is not null or typeof (Stream).

Description

[Note: This method overrides System.Xml.XmlResolver.GetEntity(System.Uri,System.String,System.Type).

]

See Also

System.Xml.XmlUrlResolver Class, System.Xml Namespace

XmlUrlResolver.ResolveUri Method

public override Uri ResolveUri(Uri baseUri, string relativeUri);

Summary

Resolves the absolute URI from the base and relative URIs.

Parameters

baseUri
The Uri specifying the base URI used to resolve relativeURI.
relativeUri
A String specifying the URI to resolve. The URI can be absolute or relative.

Return Value

A Uri containing the absolute URI, or null if relativeUri can not be resolved.

Exceptions

Exception TypeCondition
ArgumentExceptionrelativeUri is null .

Description

If relativeURI is null , it is set to System.String.Empty.

[Note: The absolute URI can be used as the base URI for any subsequent requests for entities that are relative to this URI.

This method overrides System.Xml.XmlResolver.ResolveUri(System.Uri,System.String).

]

See Also

System.Xml.XmlUrlResolver Class, System.Xml Namespace

XmlUrlResolver.Credentials Property

public override ICredentials Credentials { set; }

Summary

Sets the credentials used to authenticate Web requests.

Property Value

A ICredentials instance containing the credentials.

Description

This property is write-only.

If the virtual directory is configured to allow anonymous access, credentials are not needed and this property does not need to be set.

[Note: This property overrides System.Xml.XmlResolver.Credentials.

]

Example

The following example sets credentials for the virtual directory "http://localhost/bookstore/inventory.xml". There is no output from this example.

using System;
using System.Net;
using System.Xml;

public class App {

  public static void Main() {

    XmlTextReader xtReader =  
      new XmlTextReader("http://localhost/" +
                        "bookstore/inventory.xml");
    NetworkCredential netCredential =
      new NetworkCredential("username",
                            "password",
                            "domain");
    XmlUrlResolver xResolver = new XmlUrlResolver();
    xResolver.Credentials = netCredential;
    xtReader.XmlResolver= xResolver;
  }
}
   
The following example associates different credentials with different URIs and adds the credentials to a credential cache. The credentials can then be used to check authentication for different URIs regardless of the original source of the XML. There is no output from this example.

using System;
using System.Net;
using System.Xml;

public class App {

  public static void Main() {

    XmlTextReader xtReader =  
      new XmlTextReader("http://localhost/" +
                        "bookstore/inventory.xml");
    NetworkCredential netCredential1 =
      new NetworkCredential("username1",
                            "password1",
                            "domain1");
    NetworkCredential netCredential2 =
      new NetworkCredential("username2",
                            "password2",
                            "domain2");
    CredentialCache credCache = new CredentialCache(); 
    credCache.Add( new Uri("http://www.contoso.com/"),
                  "Basic",
                   netCredential1); 
    credCache.Add( new Uri("http://app.contoso.com/"),
                  "Basic",
                   netCredential2);
    XmlUrlResolver xResolver = new XmlUrlResolver();
    xResolver.Credentials = credCache;
    xtReader.XmlResolver= xResolver;
  }
}
   

See Also

System.Xml.XmlUrlResolver Class, System.Xml Namespace