XmlReader.LocalName XmlReader.LocalName XmlReader.LocalName XmlReader.LocalName Property

定义

当在派生类中被重写时,获取当前节点的本地名称。When overridden in a derived class, gets the local name of the current node.

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

属性值

移除了前缀的当前节点的名称。The name of the current node with the prefix removed. 例如,LocalNamebook元素<bk:book>For example, LocalName is book for the element <bk:book>.

对于没有名称的节点类型(如 TextComment 等),该属性返回 String.EmptyFor node types that do not have a name (like Text, Comment, and so on), this property returns String.Empty.

异常

在上一次异步操作完成之前调用了 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);
    }
  }
}       
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,The example uses the file, book2.xml, as input.

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

适用于

另请参阅