Line number information in XmlDocument?

Line number information in XmlDocument?

Post by Greg Alle » Fri, 12 Aug 2005 22:39:44

Is there a way to get line number information from an XmlDocument object?
I work with the various elements in the XmlDocument, I want to be able to
refer to the line number.

I found an article on extending the DOM, which seems to be exactly what I
here: (en-us,vs.80).aspx

However, while it extends XmlElement to contain the line number information,
I can't
see where it is actually setting the line number information -- SetLineInfo
doesn't seem
to be called anywhere.

I know the XmlTextReader and other classes *do* contain line number
information, but
I don't want to use those for a variety of other reasons.

Can anyone help?

-- Greg Allen

Line number information in XmlDocument?

Post by Chris Love » Sun, 14 Aug 2005 09:02:03

No it does not keep that information. But the XPathDocument does.

XPathDocument doc = new XPathDocument("..\\..\\dataset1.xsd");
XPathNavigator nav = doc.CreateNavigator();
XPathNodeIterator iter = nav.Select("*");
if (iter.MoveNext()){
XPathNavigator root = iter.Current;
IXmlLineInfo info = root as IXmlLineInfo;
Console.WriteLine(info.LineNumber +"," + info.LinePosition);