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.