XmlAttribute.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

屬性值

String

節點載入的位置;如果節點沒有基底 URI,則為 String.Empty。 屬性節點的基底 URI 與其擁有人項目的相同。 如果屬性節點沒有擁有人項目,BaseURI 會傳回 String.Empty。

範例

下列範例會顯示內容節點上的資訊,包括其基底 URI。

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   
   //Create the XmlDocument.
   XmlDocument^ doc = gcnew XmlDocument;
   doc->Load( "http://localhost/baseuri.xml" );
   
   //Display information on the attribute node. The value
   //returned for BaseURI is 'http://localhost/baseuri.xml'.
   XmlAttribute^ attr = doc->DocumentElement->Attributes[ 0 ];
   Console::WriteLine( "Name of the attribute:  {0}", attr->Name );
   Console::WriteLine( "Base URI of the attribute:  {0}", attr->BaseURI );
   Console::WriteLine( "The value of the attribute:  {0}", attr->InnerText );
}
using System;
using System.IO;
using System.Xml;

public class Sample
{
  public static void Main()
  {
    //Create the XmlDocument.
    XmlDocument doc = new XmlDocument();
    doc.Load("http://localhost/baseuri.xml");

    //Display information on the attribute node. The value
    //returned for BaseURI is 'http://localhost/baseuri.xml'.
    XmlAttribute attr = doc.DocumentElement.Attributes[0];
    Console.WriteLine("Name of the attribute:  {0}", attr.Name);
    Console.WriteLine("Base URI of the attribute:  {0}", attr.BaseURI);
    Console.WriteLine("The value of the attribute:  {0}", attr.InnerText);
  }
}
Option Explicit
Option Strict

Imports System.IO
Imports System.Xml

Public Class Sample
    
    Public Shared Sub Main()
        'Create the XmlDocument.
        Dim doc As New XmlDocument()
        doc.Load("http://localhost/baseuri.xml")
        
        'Display information on the attribute node. The value
        'returned for BaseURI is 'http://localhost/baseuri.xml'.
        Dim attr As XmlAttribute = doc.DocumentElement.Attributes(0)
        Console.WriteLine("Name of the attribute:  {0}", attr.Name)
        Console.WriteLine("Base URI of the attribute:  {0}", attr.BaseURI)
        Console.WriteLine("The value of the attribute:  {0}", attr.InnerText)
    End Sub
End Class

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


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

備註

網路 XML 檔是由使用各種萬維網聯盟 (W3C) 標準包含機制所匯總的資料區塊所組成,因此包含來自不同位置的節點。 會 BaseURI 告訴您這些節點的來源。

如需其他節點類型及其運作方式的詳細資訊 BaseURI ,請參閱 XmlNode.BaseURI

這個屬性是文件物件模型的 Microsoft 擴充功能。

適用於

另請參閱