Writing XML in a stream,,,

  • Thread starter Thread starter genc ymeri
  • Start date Start date
G

genc ymeri

Hi over there,
I would like to generate this simple XML code

<greetings>Hello</greetings>

but rather being build as a text than in a physical file. So, after I build
my whole XML code I wanted assigned to a string type variable :

String MyXML;

How can I do that without the need of writing it the XML in a file ?? Any
simple code very much will be appreciated.

Thank You in advance.
 
Thanks a lot :) :)


Richard said:
StringWriter sw = new StringWriter();
XmlTextWriter xtw = new XmlTextWriter(sw);

xtw.WriteStartElement("greetings");
xtw.WriteString("Hello");
xtw.WriteEndElement();
xtw.Close();

sw.ToString(); // --> your xml string is here...

--Richard
 
Back
Top