Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 891
user1099480 Avatar asked Oct 10 '13 07:10

user1099480


People also ask

What is the difference between XmlWriter and XmlTextWriter?

XmlWriter is an abstract class. XmlTextWriter is a specific implementation of XmlWriter .

How do you create an XmlWriter?

Overloads. Creates a new XmlWriter instance using the StringBuilder and XmlWriterSettings objects. Creates a new XmlWriter instance using the filename and XmlWriterSettings object. Creates a new XmlWriter instance using the TextWriter and XmlWriterSettings objects.

What does XmlReader create FS do?

Creates a new XmlReader instance using the specified stream with default settings. Creates a new XmlReader instance by using the specified URI and settings.


1 Answers

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
}
like image 69
Martin Tausch Avatar answered Sep 28 '22 20:09

Martin Tausch