次の方法で共有


XmlNodeReader.BaseURI プロパティ

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

Overrides Public ReadOnly Property BaseURI As String
[C#]
public override string BaseURI {get;}
[C++]
public: __property String* get_BaseURI();
[JScript]
public override function get BaseURI() : String;

プロパティ値

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

解説

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

使用例

[Visual Basic, C#, C++] ファイルを解析し、各ノードのベース URI を表示する例を次に示します。

 
Option Explicit
Option Strict

Imports System
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("https://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 'Main
End Class 'Sample

[C#] 
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("https://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

[C++] 
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;

int main()
{
   XmlNodeReader* reader = 0;

   try
   {           
      //Create and load an XmlDocument.
      XmlDocument* doc = new XmlDocument();
      doc->Load(S"https://localhost/uri.xml");

      reader = new XmlNodeReader(doc);

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

   __finally
   {
      if (reader!=0)
         reader->Close();
   }
}

この例では、入力として、 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> を格納しています。

[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

参照

XmlNodeReader クラス | XmlNodeReader メンバ | System.Xml 名前空間