Language

XmlDocument.XmlResolver プロパティ

定義

外部リソースの解決に使用する XmlResolver を設定します。

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

プロパティ値

使用する XmlResolver 。

the.NET Framework のバージョン 1.1 では、 XmlResolverを指定するには、呼び出し元が完全に信頼されている必要があります。

例外

このプロパティは null に設定され、外部 DTD またはエンティティが検出されます。

例

次の例では、DTD ファイルへの参照を含む XML ドキュメントを読み込みます。 XmlResolver プロパティは、ネットワーク リソースにアクセスするために必要な資格情報を設定するために使用されます。

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

public class Sample {

  public static void Main() {

    // Supply the credentials necessary to access the DTD file stored on the network.
    XmlUrlResolver resolver = new XmlUrlResolver();
    resolver.Credentials = CredentialCache.DefaultCredentials;

    // Create and load the XmlDocument.
    XmlDocument doc = new XmlDocument();
    doc.XmlResolver = resolver;  // Set the resolver.
    doc.Load("book5.xml");

    // Display the entity replacement text which is pulled from the DTD file.
    Console.WriteLine(doc.DocumentElement.LastChild.InnerText);
  }
} // End class
Imports System.IO
Imports System.Xml
Imports System.Net

public class Sample 

  public shared sub Main()

    ' Supply the credentials necessary access the DTD file stored on the network.
    Dim resolver as XmlUrlResolver = new XmlUrlResolver()
    resolver.Credentials = CredentialCache.DefaultCredentials

    ' Create and load the XmlDocument.
    Dim doc as XmlDocument = new XmlDocument()
    doc.XmlResolver = resolver  ' Set the resolver.
    doc.Load("book5.xml")

    ' Display the entity replacement text which is pulled from the DTD file.
    Console.WriteLine(doc.DocumentElement.LastChild.InnerText)
  
  end sub
end class

この例では、次のデータ ファイルを入力として使用します。

book5.xml

<!DOCTYPE book SYSTEM 'http://myServer/data/books.dtd'>
<book ISBN = '1-861001-57-5'>
  <title>Oberon's Legacy</title>
  <price>19.95</price>
  <misc>&h;</misc>
</book>

books.dtd

<!ELEMENT book (title,price,misc)> 
<!ATTLIST book 
   genre CDATA "novel"
   ISBN CDATA #REQUIRED>
<!ELEMENT title (#PCDATA)>
<!ELEMENT price (#PCDATA)>
<!ELEMENT misc (#PCDATA)>
<!ENTITY h "hardcover">
<!ENTITY p "paperback">

注釈

XmlResolverを使用して、DTD を読み込んだり、エンティティ参照を展開したりできます。 XmlResolver.Credentials プロパティを使用すると、セキュリティで保護されたネットワーク リソースに格納されているリソースにアクセスするための資格情報をXmlResolverに設定できます。

  • ドキュメントがXmlReaderを使用して読み込まれなかった場合 (つまり、ストリームやファイルなどを使用して読み込まれた場合)、XmlResolverのXmlDocumentは常に使用されます。

  • ドキュメントが XmlTextReaderで読み込まれた場合、 XmlTextReader のリゾルバーを使用して、DocumentType ノード内の DTD 参照を解決します。 XmlDocumentのリゾルバーは、エンティティ参照を展開するために使用されます。

  • ドキュメントが XmlValidatingReaderで読み込まれた場合、 XmlDocument の競合回避モジュールは使用されません。

  • ドキュメントがXmlReaderを拡張するクラスで読み込まれ、XmlReaderがエンティティを解決できない場合 (CanResolveEntityはfalseを返します)、XmlResolverのXmlDocumentを使用して、DocumentType ノード内のすべての参照を解決し、エンティティ参照を展開します。

Note

XmlDocumentが設定されたXmlReaderを使用してXmlResolverが読み込まれる場合、XmlResolverのXmlReaderは、XmlDocumentの完了後にLoadによってキャッシュされません。

the.NET Framework のバージョン 1.1 では、このプロパティが設定されていない場合、アプリケーションの信頼レベルによって既定の動作が決定されます。

Fully trusted code: ドキュメントでは、ユーザー資格情報のない既定の XmlUrlResolver が使用されます。 ネットワーク リソースへのアクセスに認証が必要な場合は、 XmlResolver プロパティを使用して、必要な資格情報で XmlResolver を指定します。

Semi-trusted code: XmlResolver プロパティは null に設定されます。 外部リソースは解決されません。

セキュリティと XmlResolver プロパティの詳細については、「 外部リソースの解決」を参照してください。

このプロパティは、ドキュメント オブジェクト モデル (DOM) に対する Microsoft の拡張機能です。

適用対象

こちらもご覧ください