XmlDocument.XmlResolver プロパティ
アセンブリ: System.Xml (system.xml.dll 内)

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


XmlResolver を使用して、DTD を読み込んだり、エンティティ参照を展開できます。XmlResolver.Credentials プロパティを使用すると、資格情報を XmlResolver に設定して、セキュリティ設定されたネットワーク リソース上に格納されているリソースにアクセスできます。
-
ドキュメントが XmlReader を使用して読み込まれなかった場合、つまり、ストリームやファイルなどを使用して読み込まれた場合は、常に XmlDocument の XmlResolver が使用されます。
-
ドキュメントが XmlTextReader を使用して読み込まれた場合、XmlTextReader のリゾルバを使用して DocumentType ノードのすべての DTD 参照が解決されます。XmlDocument のリゾルバを使用して、すべてのエンティティ参照が展開されます。
-
ドキュメントが XmlValidatingReader を使用して読み込まれた場合、XmlDocument のリゾルバは使用されません。
-
XmlReader を拡張するクラスを使用してドキュメントが読み込まれていて、その XmlReader がエンティティを解決できない (CanResolveEntity が false を返す) 場合は、XmlDocument の XmlResolver を使用して、DocumentType ノードの参照を解決し、エンティティ参照を展開します。
![]() |
---|
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

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


XmlDocument クラス
XmlDocument メンバ
System.Xml 名前空間
Credentials
System.Net.CredentialCache
System.Net.NetworkCredential
XmlSecureResolver
Weblioに収録されているすべての辞書からXmlDocument.XmlResolver プロパティを検索する場合は、下記のリンクをクリックしてください。

- XmlDocument.XmlResolver プロパティのページへのリンク