IXmlLineInfo.HasLineInfo Method
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Gets a value indicating whether the class can return line information.
Assembly: System.Xml (in System.Xml.dll)
Return Value
Type: System.Booleantrue if LineNumber and LinePosition can be provided; otherwise, false.
// Create the XML fragment to be parsed. string xmlFrag = @"<book> <misc> <style>paperback</style> <pages>240</pages> </misc> </book>"; // Create the XmlNamespaceManager. XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable()); // Create the XmlParserContext. XmlParserContext context = new XmlParserContext(null, nsmgr, null, XmlSpace.None); StringBuilder output = new StringBuilder(); // Create the reader. using (XmlReader reader = XmlReader.Create(new StringReader(xmlFrag), null, context)) { IXmlLineInfo lineInfo = ((IXmlLineInfo)reader); if (lineInfo.HasLineInfo()) { // Parse the XML and display each node. while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: output.Append(reader.Depth + " " + lineInfo.LineNumber + ", " + lineInfo.LinePosition); output.AppendLine("<" + reader.Name + ">"); break; case XmlNodeType.Text: output.Append(reader.Depth + " " + lineInfo.LineNumber + ", " + lineInfo.LinePosition); output.AppendLine(" " + reader.Value); break; case XmlNodeType.EndElement: output.Append(reader.Depth + " " + lineInfo.LineNumber + ", " + lineInfo.LinePosition); output.AppendLine("</" + reader.Name + ">"); break; } } } // Close the reader. } // Display the output to the TextBlock control OutputTextBlock.Text = output.ToString();
Show: