chuang4630
asked on
How do I write the xml to a string?
I need to create a XML file on the fly. The current code only writes the xml to the file as follows:
XmlTextWriter writer = new XmlTextWriter(xmlMyRequest File, Encoding.UTF8);
How do I write the xml to a string?
XmlTextWriter writer = new XmlTextWriter(xmlMyRequest
How do I write the xml to a string?
ASKER
The compiler gives me the error:
Error 4 The best overloaded method match for 'System.Xml.XmlTextWriter. XmlTextWri ter(System .IO.Stream , System.Text.Encoding)' has some invalid arguments C:\Documents and Settings\Chris Huang\My Documents\Visual Studio 2005\Projects\Hilton.CCS.B usiness\Or derShipFro mATT.cs 135 36 Hilton.CCS.Business
Error 4 The best overloaded method match for 'System.Xml.XmlTextWriter.
Try with something like:
StringBuilder sb = new StringBuilder();
XmlWriter xw = XmlTextWriter.Create(sb, ws);
// some xml writting
// xw.WriteStartElement(...);
// xw.WriteEndElement();
xw.Close();
string s = sb.ToString();
StringBuilder sb = new StringBuilder();
XmlWriter xw = XmlTextWriter.Create(sb, ws);
// some xml writting
// xw.WriteStartElement(...);
// xw.WriteEndElement();
xw.Close();
string s = sb.ToString();
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
What is ws in XmlTextWriter.Create(sb, ws);?
as mentioned in my previous post: the writer settings
XmlTextWriter xw = new XmlTextWriter(sw);