XmlNodeReader.BaseURI プロパティ

定義

現在のノードのベース URI を取得します。

public:
 virtual property System::String ^ BaseURI { System::String ^ get(); };
public override string BaseURI { get; }
member this.BaseURI : string
Public Overrides ReadOnly Property BaseURI As String

プロパティ値

現在のノードのベース URI。

次の例では、ファイルを解析し、各ノードのベース URI を表示します。

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlNodeReader^ reader = nullptr;
   try
   {
      
      //Create and load an XmlDocument.
      XmlDocument^ doc = gcnew XmlDocument;
      doc->Load( "http://localhost/uri.xml" );
      reader = gcnew XmlNodeReader( doc );
      
      //Parse the file and display the base URI for each node.
      while ( reader->Read() )
      {
         Console::WriteLine( "({0}) {1}", reader->NodeType, reader->BaseURI );
      }
   }
   finally
   {
      if ( reader != nullptr )
            reader->Close();
   }

}
using System;
using System.IO;
using System.Xml;

public class Sample
{
  public static void Main()
  {
    XmlNodeReader reader = null;

    try
    {
        //Create and load an XmlDocument.
        XmlDocument doc = new XmlDocument();
        doc.Load("http://localhost/uri.xml");

        reader = new XmlNodeReader(doc);

        //Parse the file and display the base URI for each node.
        while (reader.Read())
        {
            Console.WriteLine("({0}) {1}", reader.NodeType, reader.BaseURI);
         }
     }

     finally
     {
       if (reader!=null)
         reader.Close();
     }
  }
} // End class
Option Explicit
Option Strict

Imports System.IO
Imports System.Xml

Public Class Sample
    
    Public Shared Sub Main()
        Dim reader As XmlNodeReader = Nothing
        
        Try
            'Create and load an XmlDocument.
            Dim doc As New XmlDocument()
            doc.Load("http://localhost/uri.xml")
            
            reader = New XmlNodeReader(doc)
            
            'Parse the file and display the base URI for each node.
            While reader.Read()
                Console.WriteLine("({0}) {1}", reader.NodeType, reader.BaseURI)
            End While
        
        Finally
            If Not (reader Is Nothing) Then
                reader.Close()
            End If
        End Try
    End Sub
End Class

この例では、 uri.xmlファイル を入力として使用します。


<!-- XML fragment -->
<!DOCTYPE book [<!ENTITY s SYSTEM "tmp/style.xml">]>
<book genre="novel">
  <title>Pride And Prejudice</title>
  <misc>&s;</misc>
</book>

ファイルには style.xml XML テキスト <style>hardcover</style>が含まれています。

注釈

注意

.NET Framework 2.0 では、 クラスと Create メソッドを使用してXmlReaderSettingsインスタンスを作成XmlReaderすることをお勧めします。 これにより、.NET Frameworkで導入されたすべての新機能を最大限に活用できます。 詳細については、リファレンス ページの「解説」セクションを XmlReader 参照してください。

ネットワーク XML ドキュメントは、さまざまな W3C 標準包含メカニズムを使用して集計されたデータのチャンクで構成されるため、異なる場所からのノードが含まれます。 DTD エンティティはこの例ですが、これは DTD に限定されません。 ベース URI は、これらのノードの由来を通知します。 返されるノードのベース URI がない場合 (メモリ内文字列から解析された場合など)、String.Empty が返されます。

適用対象