外部リソースを解決するために使用する XmlResolver を設定します。
Property XmlResolver As XmlResolver
[C#]
XmlResolver XmlResolver {set;}
[C++]
public: __property virtual void set_XmlResolver(XmlResolver*);
[JScript]
public function set XmlResolver(XmlResolver);
プロパティ値
使用する XmlResolver 。
.NET Framework Version 1.1 の場合、完全に信頼されている呼び出し元だけが XmlResolver を指定できます。
例外
例外の種類 | 条件 |
---|---|
XmlException | このプロパティが null 参照 (Visual Basic では Nothing) に設定されており、外部 DTD またはエンティティが検出されました。 |
解説
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 拡張機能です。
使用例
[Visual Basic, C#, C++] 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
[C#]
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
[C++]
#using <mscorlib.dll>
#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 = new XmlUrlResolver();
resolver->Credentials = CredentialCache::DefaultCredentials;
// Create and load the XmlDocument.
XmlDocument* doc = new XmlDocument();
doc->XmlResolver = resolver; // Set the resolver.
doc->Load(S"book5.xml");
// Display the entity replacement text which is pulled from the DTD file.
Console::WriteLine(doc->DocumentElement->LastChild->InnerText);
}
[Visual Basic, C#, C++] この例では、次のデータ ファイルを入力として使用しています。
[Visual Basic, C#, C++] 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>
[Visual Basic, C#, C++] 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">
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET
参照
XmlDocument クラス | XmlDocument メンバ | System.Xml 名前空間 | Credentials | System.Net.CredentialCache | System.Net.NetworkCredential | XmlSecureResolver