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

XmlReader from another using XmlParserContext and XmlReaderSettings

P: n/a
Jen
My main question: "How can I get a TextReader or Stream object from an
existing XmlReader?". Read on for more:

I have an existing XmlReader. Let's call it reader1. I'm creating
another reader, reader2, after creating new XmlReaderSettings and a new
XmlParserContext.

// customContext and customSettings may or may not make use
reader1's properties
XmlParserContext customContext = new XmlParserContext(...);

XmlReaderSettings customSettings = new
XmlReaderSettings(...);

// This won't work, because reader1 isn't a TextReader,
Stream or URI.
XmlReader reader2 = XmlReader.Create(reader1,
customSettings, customContext);

I have to use an overload of XmlReader.Create() that takes both an
XmlReaderSettings and an XmlParserContext as arguments, because they
cannot be set AFTER the XmlReader has been created. (Actually, Settings
can be set post-creation, but not the context, and customContext is
important.)

Here's the problem. XmlReader.Create() has _three_ overloads that take
both XmlParserContext and XmlReaderSettings as arguments. But none of
these overloads takes an existing XmlReader. Here are the overloads:

1. XmlReader.Create (TextReader, XmlReaderSettings, XmlParserContext)
2. XmlReader.Create (Stream, XmlReaderSettings, XmlParserContext)
3. XmlReader.Create (String, XmlReaderSettings, XmlParserContext) //
String is the URI

I believe that both (1) and (2) should work no matter what XmlReader
reader1 is. What's the easiest way to get a TextReader or Stream object
from an existing XmlReader? I don't think that there are easier ways to
do what I'm trying to do.

Jan 16 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.