By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,106 Members | 2,686 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,106 IT Pros & Developers. It's quick & easy.

XmlSerializer/XmlTextWriter all data on one line

P: n/a
I'm an XML newb.
I'm serializing a class and when I inspect the xml file, all the data is on
one line rather than being nested and indented

Is that normal?

<code>
StreamWriter sw = new StreamWriter(m_optionsXmlFilePath, false);
XmlSerializer xmlSerializer = new XmlSerializer(typeof(Options));
XmlTextWriter xmlTextWriter = new XmlTextWriter(sw);

xmlSerializer.Serialize(xmlTextWriter, this);
xmlTextWriter.Close();
</code>
Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hello!
I'm serializing a class and when I inspect the xml file, all the data is on
one line rather than being nested and indented

Is that normal?
Yes, it is.

Use the indentation-property on XmlTextWriter to generate a
human-reader-friendly output:
<code>
StreamWriter sw = new StreamWriter(m_optionsXmlFilePath, false);
XmlSerializer xmlSerializer = new XmlSerializer(typeof(Options));
XmlTextWriter xmlTextWriter = new XmlTextWriter(sw); xmlTextWriter.Formatting = Formatting.Indented
xmlSerializer.Serialize(xmlTextWriter, this);
xmlTextWriter.Close();
</code>


see also:
<http://msdn2.microsoft.com/en-us/library/system.xml.xmltextwriter.formatting>

--
Pascal Schmitt
Nov 12 '05 #2

P: n/a
Perfect, thank you so much!
"Pascal Schmitt" <ne*******@cebra.nu> wrote in message
news:Oi*************@TK2MSFTNGP12.phx.gbl...
Hello!
I'm serializing a class and when I inspect the xml file, all the data is on one line rather than being nested and indented

Is that normal?
Yes, it is.

Use the indentation-property on XmlTextWriter to generate a
human-reader-friendly output:
<code>
StreamWriter sw = new StreamWriter(m_optionsXmlFilePath, false);
XmlSerializer xmlSerializer = new XmlSerializer(typeof(Options));
XmlTextWriter xmlTextWriter = new XmlTextWriter(sw);

xmlTextWriter.Formatting = Formatting.Indented

xmlSerializer.Serialize(xmlTextWriter, this);
xmlTextWriter.Close();
</code>


see also:

<http://msdn2.microsoft.com/en-us/lib...iter.formattin
g>
--
Pascal Schmitt

Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.