My xml file is displayed as a long string. How do I insert newlines?
-
I am using the XML namespace functions and classes in C# to create an XML file dynamically. However, when I look at the file in notepad, it's just one really really long string on the first line. How do I include the appropriate newline and tab characters so that the file looks like a normal, logical XML file? I cant just use the normal "\n" character can I? Do I use functions from the XmlWhitespace class or something??
-
I am using the XML namespace functions and classes in C# to create an XML file dynamically. However, when I look at the file in notepad, it's just one really really long string on the first line. How do I include the appropriate newline and tab characters so that the file looks like a normal, logical XML file? I cant just use the normal "\n" character can I? Do I use functions from the XmlWhitespace class or something??
You need to pass an
XmlWriter
to theSave
method:void SaveXml(XmlDocument doc, Stream s, Encoding encoding)
{
XmlTextWriter xtw = new XmlTextWriter(s, encoding);
xtw.Formatting = Formatting.Indented;
xtw.Indentation = 1;
xtw.IndentChar = '\t';doc.Save(xtw);
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer