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

屬性值

目前節點的命名空間 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

適用於