XmlReader.LocalName Property

May 11, 2014

When overridden in a derived class, gets the local name of the current node.

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)

public abstract string LocalName { get; }

Property Value

Type: System.String
The name of the current node with the prefix removed. For example, LocalName is book for the element <bk:book>.
For node types that do not have a name (like Text, Comment, and so on), this property returns String.Empty.



StringBuilder output = new StringBuilder();

String xmlString =
    @"<book xmlns:bk='urn:samples'>
    <title>Pride And Prejudice</title>
    <bk:genre>novel</bk:genre>
</book>";

// Create an XmlReader
using (XmlReader reader = XmlReader.Create(new StringReader(xmlString)))
{
    // 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)
                output.Append("<" + reader.LocalName + ">");
            else
            {
                output.Append("<" + reader.Prefix + ":" + reader.LocalName + ">");
                output.AppendLine(" The namespace URI is " + reader.NamespaceURI);
            }
        }
    }
}

OutputTextBlock.Text = output.ToString();


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft