XmlNodeReader.LocalName Propriedade
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Obtém o nome local do nó atual.
public:
virtual property System::String ^ LocalName { System::String ^ get(); };
public override string LocalName { get; }
member this.LocalName : string
Public Overrides ReadOnly Property LocalName As String
Valor de Propriedade
O nome do nó atual com o prefixo removido. Por exemplo, LocalName é book para o elemento <bk:book>.
Para tipos de nós que não têm nome (como Text, Comment, e assim sucessivamente), esta propriedade devolve String.Empty.
Exemplos
O exemplo seguinte mostra o nome local de cada nó e, se existirem, o prefixo e o espaço de nomes URI.
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main()
{
XmlNodeReader reader = null;
try
{
//Create and load the XML document.
XmlDocument doc = new XmlDocument();
doc.LoadXml("<book xmlns:bk='urn:samples'> " +
"<title>Pride And Prejudice</title>" +
"<bk:genre>novel</bk:genre>" +
"</book>");
//Load the XmlNodeReader
reader = new XmlNodeReader(doc);
//Parse the XML. 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);
}
}
}
}
finally
{
if (reader != null)
reader.Close();
}
}
} // End class
Imports System.IO
Imports System.Xml
Public Class Sample
Public Shared Sub Main()
Dim reader As XmlNodeReader = Nothing
Try
'Create and load the XML document.
Dim doc As New XmlDocument()
doc.LoadXml("<book xmlns:bk='urn:samples'> " & _
"<title>Pride And Prejudice</title>" & _
"<bk:genre>novel</bk:genre>" & _
"</book>")
'Load the XmlNodeReader
reader = New XmlNodeReader(doc)
'Parse the XML. 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
Finally
If Not (reader Is Nothing) Then
reader.Close()
End If
End Try
End Sub
End Class
Observações
Note
Para tirar partido das funcionalidades mais recentes, a prática recomendada é criar XmlReader instâncias usando a XmlReaderSettings classe e o Create método. Para mais informações, consulte a secção de Observações na XmlReader página de referência.