XmlDocument.XmlResolver プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > XmlDocument.XmlResolver プロパティの意味・解説 

XmlDocument.XmlResolver プロパティ

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

名前空間: System.Xml
アセンブリ: System.Xml (system.xml.dll 内)
構文構文

Public Overridable WriteOnly
 Property XmlResolver As XmlResolver
Dim instance As XmlDocument
Dim value As XmlResolver

instance.XmlResolver = value
public virtual XmlResolver XmlResolver { set;
 }
public:
virtual property XmlResolver^ XmlResolver {
    void set (XmlResolver^ value);
}
/** @property */
public void set_XmlResolver (XmlResolver value)
public function set XmlResolver
 (value : XmlResolver)

プロパティ値
使用する XmlResolver。 .NET Framework Version 1.1 の場合、完全に信頼されている呼び出し元だけが XmlResolver を指定できます。

例外例外
例外の種類条件

XmlException

このプロパティが null 参照 (Visual Basic では Nothing) に設定されており、外部 DTD またはエンティティが検出されました。

解説解説

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

メモメモ

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

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

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

Semi-trusted code: XmlResolver プロパティが null 参照 (Visual Basic では Nothing) に設定されています。外部リソースが解決されていません。

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

このプロパティは、DOM (Document Object Model) に対する Microsoft 拡張機能です。

使用例使用例

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

Imports System
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
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
#using <System.dll>
#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
using namespace System::Net;
int main()
{
   
   // Supply the credentials necessary to access the DTD file stored
 on the network.
   XmlUrlResolver^ resolver = gcnew XmlUrlResolver;
   resolver->Credentials = CredentialCache::DefaultCredentials;
   
   // Create and load the XmlDocument.
   XmlDocument^ doc = gcnew 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 );
}

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

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">
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlDocument クラス
XmlDocument メンバ
System.Xml 名前空間
Credentials
System.Net.CredentialCache
System.Net.NetworkCredential
XmlSecureResolver



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

XmlDocument.XmlResolver プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



XmlDocument.XmlResolver プロパティのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS