共用方式為


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

屬性值

節點載入的位置,或若節點沒有基礎 URI,則為 String.Empty。 屬性節點的基礎 URI 與其擁有者元素相同。 如果屬性節點沒有擁有者元素,則 BaseURI 回傳 String.Empty。

範例

以下範例顯示屬性節點的資訊,包括其基礎 URI。

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 對文件物件模型(DOM)的擴充。

適用於

另請參閱