Current line number from a System.Xml.XmlReader (C# & .Net)

Danielb picture Danielb · Mar 7, 2009 · Viewed 11.3k times · Source

Does anyone know how I can get the current line number of an System.Xml.XmlReader? I am trying to record where in a file I find Xml elements.

Answer

Daniel LeCheminant picture Daniel LeCheminant · Mar 7, 2009

Take advantage of the IXmlLineInfo interface supported by an XmlReader:

IXmlLineInfo xmlInfo = (IXmlLineInfo)reader;
int lineNumber = xmlInfo.LineNumber;