user1099480 user1099480 - 1 month ago 24
C# Question

xmlwriter as input for xmlreader

I am trying to create a xml-structre from a name/value-pairs. This works with a xmlwriter. Now I would like to transform this xml.

I think that the best way is to use the xmlwriter as source for the xmlreader to to the transform. But I don't know how to set the xmlwriter as source for the xmlreader.

How can I do this?

Answer

You could use a MemoryStream for example.

MemoryStream stream = new MemoryStream();
using (XmlWriter writer = XmlWriter.Create(stream))
{
    // Do some stuff with writer
}

stream.Seek(0, SeekOrigin.Begin); // Reset stream position to read from the beginning.

using (XmlReader reader = XmlReader.Create(stream))
{
    // Do some stuff with reader
}
Comments