I'd like to use tabs, or at least more than 2 spaces per indent level. IIRC there are options available to adjust this when using serialization to write a class out; but I don't see any way to adjust the behavior when calling MyDataSet.WriteXml(filename)
.
views:
56answers:
2
+2
A:
You need to use a XmlTextWriter
if you want to influence the layout of your XML being saved:
XmlTextWriter xtw = new XmlTextWriter(filename, Encoding.UTF8);
xtw.Formatting = Formatting.Indented;
xtw.Indentation = 4;
xtw.IndentChar = '\t';
and then write out your data set using that XmlTextWriter
:
MyDataSet.WriteXml(xtw);
marc_s
2009-12-11 22:03:55
Wouldn't that produce an indentation of 4 tab characters? ;)
Robert Jeppesen
2009-12-11 22:06:43
yes, in that case, it would. Adjust as needed :-)
marc_s
2009-12-11 22:09:18
+1
A:
Use one of the overloads that accepts an XmlWriter
, and pass in an XmlWriter
configured with an XmlWriterSettings
object that has the options you want.
XmlWriterSettings settings = new XmlWriterSettings
{
Indent = true,
IndentChars = "\t"
};
using (var writer = XmlWriter.Create("file.xml", settings))
{
ds.WriteXml(writer);
}
John Saunders
2009-12-11 22:04:24