
December 14th, 2010, 09:33 PM
|
|
Registered User
|
|
Join Date: Aug 2010
Posts: 5
Time spent in forums: 54 m
Reputation Power: 0
|
|
|
Formatting with xmlwriter
I am using a little function (below) to format some xml before writing it out to file. It works pretty good, but there is one thing I'd like to change if possible. When it encounters a node without a value, it breaks it out to two lines. I want it to stay on one line. For example, it will format a node as such:
<emptytag>
</emptytag>
I want it to be as such:
<emptytag></emptytag>
Is it possible to get xmlwriter to do this?
Code:
static public void Beautify(XmlDocument doc)
{
try
{
StringBuilder sb = new StringBuilder();
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.IndentChars = ""; //this seems to do nothing
//settings.IndentChars = (ControlChars.Tab)
settings.NewLineChars = "\r\n";
settings.NewLineHandling = NewLineHandling.Replace;
XmlWriter writer = XmlWriter.Create(sb, settings);
doc.Save(writer);
writer.Flush();
writer.Close();
}
catch
{
MessageBox.Show("Could not beautify " + doc.BaseURI);
}
}
|