472,133 Members | 1,177 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,133 software developers and data experts.

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 7445
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 leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.