Gilgamesh wrote:
I got the XML document written into StringWriter. However, my
ultimate goal is to store XML document in a text field in SQL database. I
tried the StringMethod method called Write, but this method inserts \r\n at
the end of each element. Is there any way to get the XML document without
line return characters?
That depends solely on the Formatting settings of the XmlTextWriter e.g.
you can do
StringWriter stringWriter = new StringWriter();
XmlTextWriter xmlWriter = new XmlTextWriter(stringWriter);
xmlWriter.Formatting = Formatting.None;
xmlWriter.WriteStartElement("gods");
xmlWriter.WriteElementString("god", "Kibo");
xmlWriter.WriteElementString("god", "Xibo");
xmlWriter.WriteEndElement();
xmlWriter.Flush();
Console.WriteLine("XML is:\r\n{0}", stringWriter.ToString());
and the result is alike
XML is:
<gods><god>Kibo</god><god>Xibo</god></gods>
or you can set the writer to indent e.g.
StringWriter stringWriter = new StringWriter();
XmlTextWriter xmlWriter = new XmlTextWriter(stringWriter);
xmlWriter.Formatting = Formatting.Indented;
xmlWriter.WriteStartElement("gods");
xmlWriter.WriteElementString("god", "Kibo");
xmlWriter.WriteElementString("god", "Xibo");
xmlWriter.WriteEndElement();
xmlWriter.Flush();
Console.WriteLine("XML is:\r\n{0}", stringWriter.ToString());
and the output is alike
XML is:
<gods>
<god>Kibo</god>
<god>Xibo</god>
</gods>
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/