XElement.Load(TextReader, LoadOptions.SetLineInfo) : XML Load « XML LINQ « VB.Net






XElement.Load(TextReader, LoadOptions.SetLineInfo)

  

Imports System
Imports System.IO

Imports System.Xml
Imports System.Xml.XPath

Public Class MainClass

    Public Shared Sub Main()
        Dim sr As TextReader = New StringReader( _
            "<Root>" & Environment.NewLine & _
            "  <Child>" & Environment.NewLine & _
            "    <GrandChild1/>" & Environment.NewLine & _
            "    <GrandChild2/>" & Environment.NewLine & _
            "  </Child>" & Environment.NewLine & _
            "</Root>")
        Dim po As XElement = XElement.Load(sr, LoadOptions.SetLineInfo)
        For Each e As XElement In po.DescendantsAndSelf()
            Console.WriteLine("{0}{1}{2}", _
                ("".PadRight(e.Ancestors().Count() * 2) & e.Name.ToString).PadRight(20), _
                (DirectCast(e, IXmlLineInfo)).LineNumber.ToString().PadRight(5), _
                (DirectCast(e, IXmlLineInfo)).LinePosition)
        Next
        
    End Sub
End Class

   
    
  








Related examples in the same category

1.using XElement.Parse to load Xml from String
2.XElement.Parse (String) Loads an XElement from a string that contains XML.
3.XElement.Parse Method (String, LoadOptions) Loads an XElement from a string that contains XML
4.XElement.Parse(String, LoadOptions.SetLineInfo)
5.Load the Employees.xml and store the contents into an XElement object.
6.XElement.Load (String) loads an XElement from a file.
7.XElement.Load (String, LoadOptions) loads an XElement from a file
8.XElement.Load("Order.xml", LoadOptions.SetBaseUri Or LoadOptions.SetLineInfo)
9.XElement.Load (TextReader) loads an XElement from a TextReader.
10.XElement.Load(TextReader, LoadOptions) loads an XElement from a TextReader