XElement
(actually XObject
) implements the IXmlLineInfo
interface, so you can use it:
IXmlLineInfo info = category;
int lineNumber = info.LineNumber;
Note that line information is not always available, you need to call the HasLineInfo
method to check if the information is available. You can specify LoadOptions.SetLineInfo
when you load the document with XDocument.Load