Partager via


IXmlLineInfo Interface

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

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

Syntax

'Declaration
Public Interface IXmlLineInfo
public interface IXmlLineInfo

The IXmlLineInfo type exposes the following members.

Properties

  Name Description
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 LineNumber Gets the current line number.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 LinePosition Gets the current line position.

Top

Methods

  Name Description
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 HasLineInfo Gets a value indicating whether the class can return line information.

Top

Examples

' Create the XML fragment to be parsed.
Dim xmlFrag As String = _
    "<book>" & _
         "<misc>" & _
             "<style>paperback</style>" & _
             "<pages>240</pages>" & _
         "</misc>" & _
     "</book>"

' Create the XmlNamespaceManager.
Dim nsmgr As XmlNamespaceManager = New XmlNamespaceManager(New NameTable())

' Create the XmlParserContext.
Dim context As New XmlParserContext(Nothing, nsmgr, Nothing, XmlSpace.None)

Dim output As New StringBuilder()
' Create the reader.
Using reader As XmlReader = XmlReader.Create(New StringReader(xmlFrag), Nothing, context)

    Dim lineInfo As IXmlLineInfo = CType(reader, IXmlLineInfo)
    If lineInfo.HasLineInfo() Then

        ' Parse the XML and display each node.
        While reader.Read()
            Select Case reader.NodeType
                Case XmlNodeType.Element
                    output.Append(reader.Depth.ToString() + " " + _
                        lineInfo.LineNumber.ToString() + ", " + _
                        lineInfo.LinePosition.ToString())
                    output.AppendLine("<" + reader.Name + ">")
                Case XmlNodeType.Text
                    output.Append(reader.Depth.ToString() + " " + _
                        lineInfo.LineNumber.ToString() + ", " + _
                        lineInfo.LinePosition.ToString())
                    output.AppendLine("  " + reader.Value)
                Case XmlNodeType.EndElement
                    output.Append(reader.Depth.ToString() + " " + _
                        lineInfo.LineNumber.ToString() + ", " + _
                        lineInfo.LinePosition.ToString())
                    output.AppendLine("</" + reader.Name + ">")
            End Select
        End While
    End If
End Using

' Display the output to the TextBlock control
OutputTextBlock.Text = output.ToString()
// 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();

Version Information

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

Platforms

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

See Also

Reference