Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

XmlReader and LineNumber

4 views
Skip to first unread message

jonfroehlich

unread,
Jul 11, 2006, 5:41:37 PM7/11/06
to
According to the MSDN documentation within the XmlTextReader class for
.NET 2.0, the recommended practice to create XmlReader instances is
using the XmlReaderSettings class and the XmlReader.Create() method.
However, the problem is, the XmlReader class does not expose certain
properties that I need, e.g., LineNumber, LinePosition, etc. I would
like to follow Microsoft's recommended practices, but I'm not sure how
I can get XmlTextReader functionality out of XmlReader.

Should I instantiate a XmlTextReader object and pass this to the
XmlReader.Create() method and then access this underlying text reader
to obtain the info I need? Or is there some way to get the
XmlReader.Create() method to return a XmlTextReader object? Or should I
ignore their suggestion and simply create an XmlTextReader object
manually and not use the XmlReader.Create() method at all.

I asked this question back on May 18th in
microsoft.public.dotnet.languages.csharp but did not receive a
response, hopefully I will here.

Thanks!

Zafar Abbas

unread,
Jul 12, 2006, 12:38:42 PM7/12/06
to
The reader obtained via XmlReader.Create supports the IXmlLinfInfo interface
from which you can access the line properties:

reader = XmlReader.Create (...)

IXmlLineInfo info = reader as IXmlLineInfo;
Console.WriteLine(info.LineNumber);
Console.WriteLine(info.LinePosition);

this should print your line numbers of the current node.


Thanks,
Zafar
"jonfroehlich" <jonfro...@gmail.com> wrote in message
news:1152654097.7...@s13g2000cwa.googlegroups.com...

jonfroehlich

unread,
Jul 25, 2006, 11:17:16 PM7/25/06
to
Zafar,

This works great! I didn't realize IXmlLineInfo existed before :-|

0 new messages