LineNumber Property
Collapse the table of content
Expand the table of content

IXmlLineInfo.LineNumber Property

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Gets the current line number.

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

'Declaration
ReadOnly Property LineNumber As Integer

Property Value

Type: System.Int32
The current line number or 0 if no line information is available (for example, HasLineInfo returns false).

This property is used primarily for error reporting, but can be called at any time. The starting value is 1. Combined with LinePosition, a value of 1,1 indicates the start of a document.


' 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()


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft