XmlReader.LocalName Property
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
When overridden in a derived class, gets the local name of the current node.
Assembly: System.Xml (in System.Xml.dll)
Property Value
Type: System.StringThe 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();
Show: