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;
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>が含まれています。

注釈

Note

新しい機能を利用するには、XmlReader クラスと XmlReaderSettings メソッドを使用してCreate インスタンスを作成することをお勧めします。 詳細については、「 XmlReader リファレンス」ページの「解説」セクションを参照してください。

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

適用対象