XmlReader.NamespaceURI 屬性

定義

在衍生類別中覆寫時,取得讀取器所在節點的命名空間 URI (如 W3C 命名空間規格中所定義)。

public:
 abstract property System::String ^ NamespaceURI { System::String ^ get(); };
public abstract string NamespaceURI { get; }
member this.NamespaceURI : string
Public MustOverride ReadOnly Property NamespaceURI As String

屬性值

String

目前節點的命名空間 URI,否則為空字串。

例外狀況

在先前的非同步作業完成前呼叫了 XmlReader 方法。 在此情況下,會擲回 InvalidOperationException 與「非同步作業已經在進行中」的訊息。

範例

下列範例會顯示每個節點的本機名稱,如果存在,則會顯示前置詞和命名空間 URI。

XmlReader reader = XmlReader.Create("book2.xml");

// Parse the file.  If they exist, display the prefix and
// namespace URI of each node.
while (reader.Read()) {
  if (reader.IsStartElement()) {
    if (reader.Prefix==String.Empty)
                {
                    Console.WriteLine("<{0}>", reader.LocalName);
                }
                else {
      Console.Write("<{0}:{1}>", reader.Prefix, reader.LocalName);
      Console.WriteLine(" The namespace URI is " + reader.NamespaceURI);
    }
  }
}
reader.Close();
Dim reader As XmlReader = XmlReader.Create("book2.xml")
        
' Parse the file.  If they exist, display the prefix and 
' namespace URI of each node.
While reader.Read()
  If reader.IsStartElement() Then
    If reader.Prefix = String.Empty Then
      Console.WriteLine("<{0}>", reader.LocalName)
    Else
      Console.Write("<{0}:{1}>", reader.Prefix, reader.LocalName)
      Console.WriteLine(" The namespace URI is " + reader.NamespaceURI)
    End If
  End If
End While
reader.Close()

此範例會使用 檔案 book2.xml 做為輸入。

<book xmlns:bk='urn:samples'>
  <title>Pride And Prejudice</title>
  <bk:genre>novel</bk:genre>
</book>

備註

此屬性僅與 ElementAttribute 節點相關。

適用於