By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,353 Members | 1,247 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,353 IT Pros & Developers. It's quick & easy.

XmlReader and LineNumber

P: n/a
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!

Jul 11 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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" <jo**********@gmail.comwrote in message
news:11**********************@s13g2000cwa.googlegr oups.com...
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!

Jul 12 '06 #2

P: n/a
Zafar,

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

Zafar Abbas wrote:
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" <jo**********@gmail.comwrote in message
news:11**********************@s13g2000cwa.googlegr oups.com...
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!
Jul 26 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.