XmlReader.NamespaceURI 属性


当在派生类中被重写时,获取读取器定位在其上的节点的命名空间 URI(采用 W3C 命名空间规范中定义的形式)。When overridden in a derived class, gets the namespace URI (as defined in the W3C Namespace specification) of the node on which the reader is positioned.

 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;否则为空字符串。The namespace URI of the current node; otherwise an empty string.


在上一次异步操作完成之前调用了 XmlReader 方法。An XmlReader method was called before a previous asynchronous operation finished. 在此情况下,会引发 InvalidOperationException 并显示消息“异步操作已在进行中。”In this case, InvalidOperationException is thrown with the message "An asynchronous operation is already in progress."


下面的示例显示每个节点的本地名称,并显示前缀和命名空间 URI (如果存在)。The following example displays the local name of each node, and, if they exist, the prefix and namespace 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);
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)
      Console.Write("<{0}:{1}>", reader.Prefix, reader.LocalName)
      Console.WriteLine(" The namespace URI is " + reader.NamespaceURI)
    End If
  End If
End While

该示例使用文件(book2.xml)作为输入。The example uses the file, book2.xml, as input.

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


此属性 Element 仅与和 Attribute 节点相关。This property is relevant to Element and Attribute nodes only.