I have a WCF service that needs to return a string of XML. But it seems like the writer only wants to build up a file, not a string. I tried:
string nextXMLstring = "";
using (XmlWriter writer = XmlWriter.Create(nextXMLstring))
This generates an error saying nextXMLstring doesnt have a file path. It wants something like:
using (XmlWriter writer = XmlWriter.Create("nextXMLstring.xml"))
How can I build up my XML and then return it as a string??
Thanks!!
You need to create a StringWriter, and pass that to the XmlWriter.
The string overload of the XmlWriter.Create is for a filename.
E.g.