469,299 Members | 2,050 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,299 developers. It's quick & easy.

XmlSerializer/XmlTextWriter all data on one line

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
2 7310
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
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.

Similar topics

8 posts views Thread by Harris Boyce | last post: by
reply views Thread by Magne Ryholt | last post: by
3 posts views Thread by grs | last post: by
3 posts views Thread by Loui Mercieca | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.