Get line number and line position
using System;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using System.Collections;
using System.Collections.Generic;
public class MainClass
{
public static void Main()
{
XElement po = XElement.Load("PurchaseOrder.xml", LoadOptions.SetBaseUri | LoadOptions.SetLineInfo);
string[] splitUri = po.BaseUri.Split('/');
Console.WriteLine("BaseUri: {0}", splitUri[splitUri.Length - 1]);
foreach (XElement e in po.DescendantsAndSelf())
{
Console.WriteLine(e.Ancestors().Count());
Console.WriteLine(e.Name);
Console.WriteLine(((IXmlLineInfo)e).LineNumber);
Console.WriteLine(((IXmlLineInfo)e).LinePosition);
}
}
}
Related examples in the same category