XmlReader.LocalName Property

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>

// 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 + ">");
                output.Append("<" + reader.Prefix + ":" + reader.LocalName + ">");
                output.AppendLine(" The namespace URI is " + reader.NamespaceURI);

OutputTextBlock.Text = output.ToString();


Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions