Magnus wrote:
can anyone help me on how to create and manipulate a xmttextwriter without
having to craete a physical file.
I have an application that should return data in xml. But I do not want to
create a file and then delete it.
Where does the application need to return the data to? If it needs to
return the data to a stream or network connection you can open an
XmlTextWriter on a stream.
You can also open an XmlTextWriter on a MemoryStream and create the XML
in memory.
Or you can ceate an XmlTextWriter on a StringWriter and simply read out
the string at the end as in the following example:
StringWriter stringWriter = new StringWriter();
XmlTextWriter xmlWriter = new XmlTextWriter(stringWriter);
xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement("gods");
xmlWriter.WriteElementString("god", "Kibo");
xmlWriter.WriteEndDocument();
xmlWriter.Close();
Console.WriteLine(stringWriter.ToString());
which writes
<?xml version="1.0" encoding="utf-16"?><gods><god>Kibo</god></gods>
to the console.
--
Martin Honnen
http://JavaScript.FAQTs.com/