Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

IXmlLineInfo Interface

Provides an interface to enable a class to return line and position information.

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)
public interface IXmlLineInfo

The IXmlLineInfo type exposes the following members.

  NameDescription
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360LineNumberGets the current line number.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360LinePositionGets the current line position.
Top
  NameDescription
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360HasLineInfoGets a value indicating whether the class can return line information.
Top

// 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();


Silverlight

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.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.