473,503 Members | 1,638 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7565
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4146
by: Integer Software | last post by:
Hi. I have a really simple set of classes that writes 2 pathnames to a xml file. I can write the default ok. Then if I change 1 pathname to a shorter one, then rewrite the xml file, the remains...
5
5407
by: Stuart Robertson | last post by:
I am trying to find a solution that will allow me to use XmlSerializer to serialize/deserialize a collection of objects where a given object is shared between two or more other objects, and not...
8
3542
by: Harris Boyce | last post by:
Hello, I'm trying to use the FOR XML EXPLICIT clause with SQL Server to deserialize data from my database into a strongly-typed collection object that I will use throughout my application. I...
0
2006
by: Magne Ryholt | last post by:
Have a class with a public property named "TheFirstPropertyOfArrayListType" of type ArrayList, property has attribute XmlElement to describe the contents of the ArrayList, the contents is a public...
0
9706
by: Riley Phelps | last post by:
When I use the XML Serializer in the following example, the first Serialize (with the class Pets) works, but the second (with the cplaa Pets2) fails. Which arrtubute nedds to be applied to make the...
3
17714
by: grs | last post by:
I am using some Microsoft examples that: 1. Serialize an object using XmlSerializer and write a file out to the harddrive. 2. Read back in the file using XmlDocument.Load and populate a string. ...
3
4487
by: Loui Mercieca | last post by:
Hi, I have created a class, named FormField , which basically contains two fields, name and value. I have set the tag before the class and the field is set as an XmlAttribute whil the name as...
3
10371
by: stax | last post by:
Hello, can somebody tell me how to serialize/deserialize a object containing a multi line string using the XmlSerializer class. One of the both windows linefeed chars get dumped somewhere down...
4
6841
by: SteveT | last post by:
I have a data structure that I am writing to an XML file using XmlSerializer. XmlSerializer xSer = new XmlSerializer(typeof(MyData)); StreamWriter sw = new StreamWriter("SomeData.xml");...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7086
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7280
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.