Επεξεργασία

Κοινή χρήση μέσω


XmlReaderSettings.XmlResolver Property

Definition

Sets the XmlResolver used to access external documents.

public:
 property System::Xml::XmlResolver ^ XmlResolver {  void set(System::Xml::XmlResolver ^ value); };
public System.Xml.XmlResolver? XmlResolver { set; }
public System.Xml.XmlResolver XmlResolver { set; }
member this.XmlResolver : System.Xml.XmlResolver
Public Property XmlResolver As XmlResolver

Property Value

An XmlResolver used to access external documents. If set to null, an XmlException is thrown when the XmlReader tries to access an external resource. The default is a new XmlUrlResolver with no credentials. Starting with the .NET Framework 4.5.2, this setting has a default value of null.

Examples

The following example creates an XmlReader that uses an XmlSecureResolver with default credentials.

// Create an XmlSecureResolver with default credentials.
XmlSecureResolver myResolver = new XmlSecureResolver(new XmlUrlResolver(), "http://serverName/data/");
myResolver.Credentials = CredentialCache.DefaultCredentials;

XmlReaderSettings settings = new XmlReaderSettings();
settings.XmlResolver = myResolver;

// Create the reader.
XmlReader reader = XmlReader.Create("http://serverName/data/books.xml", settings);
' Create an XmlSecureResolver with default credentials.
Dim myResolver As New XmlSecureResolver(New XmlUrlResolver(), "http://serverName/data/")
myResolver.Credentials = CredentialCache.DefaultCredentials

Dim settings As New XmlReaderSettings()
settings.XmlResolver = myResolver

' Create the reader.
Dim reader As XmlReader = XmlReader.Create("http://serverName/data/books.xml", settings)

Remarks

The XmlResolver is used to locate and open an XML instance document, or to locate and open any external resources referenced by the XML instance document. This can include entities, DTD, or schemas. The XmlResolver.Credentials property can be used to specify any credentials required for network authentication.

Important

Because the XmlResolver can contain sensitive information such as user credentials, you should be careful when caching XmlReaderSettings objects, or when passing the XmlReaderSettings object from one component to another.

An XmlSecureResolver can be used to access external documents. The XmlSecureResolver class helps to secure another implementation of XmlResolver by wrapping the XmlResolver object and restricting the resources that the underlying XmlResolver has access to.

The ProcessInlineSchema and ProcessSchemaLocation validation flags of an XmlReaderSettings object are not set by default. When these flags are set, the XmlResolver of the XmlReaderSettings object is used to resolve schema locations encountered in the instance document in the XmlReader. If the XmlResolver object is null, schema locations are not resolved even if the ProcessInlineSchema and ProcessSchemaLocation validation flags are set.

Schemas added during validation add new types and can change the validation outcome of the document being validated. As a result, external schemas should only be resolved from trusted sources.

Applies to

See also