XmlTextReader.BaseURI 屬性

定義

取得目前節點的基底 (Base) URI。

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

屬性值

String

目前節點的基底 URI。

範例

下列範例會顯示每個節點的基底 URI。

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlTextReader^ reader = nullptr;
   try
   {
      
      //Load the reader with the XML file.
      reader = gcnew XmlTextReader( "http://localhost/baseuri.xml" );
      
      //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()
  {
    XmlTextReader reader = null;

    try
    {
        //Load the reader with the XML file.
        reader = new XmlTextReader("http://localhost/baseuri.xml");

        //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 XmlTextReader = Nothing
      
      Try
         'Load the reader with the XML file.
         reader = New XmlTextReader("http://localhost/baseuri.xml")
         
         '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

此範例會使用 檔案 baseuri.xml ,作為輸入。


<!-- XML fragment -->
<book genre="novel">
  <title>Pride And Prejudice</title>
</book>

備註

注意

從 .NET Framework 2.0 開始,建議您使用 XmlReader.Create 方法來建立 XmlReader 實例,以利用新功能。

網路 XML 檔是由使用各種 W3C 標準包含機制匯總的資料區塊所組成,因此包含來自不同位置的節點。 DTD 實體是這種情況的範例,但這不限於 DTD。 基底 URI 會告訴您這些節點的來源。 例如,如果沒有傳回節點的基底 URI (,則會從記憶體內部字串剖析) String.Empty

適用於

另請參閱