473,795 Members | 2,867 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_ optionsXmlFileP ath, false);
XmlSerializer xmlSerializer = new XmlSerializer(t ypeof(Options)) ;
XmlTextWriter xmlTextWriter = new XmlTextWriter(s w);

xmlSerializer.S erialize(xmlTex tWriter, this);
xmlTextWriter.C lose();
</code>
Nov 12 '05 #1
2 7600
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_ optionsXmlFileP ath, false);
XmlSerializer xmlSerializer = new XmlSerializer(t ypeof(Options)) ;
XmlTextWriter xmlTextWriter = new XmlTextWriter(s w); xmlTextWriter.F ormatting = Formatting.Inde nted
xmlSerializer.S erialize(xmlTex tWriter, this);
xmlTextWriter.C lose();
</code>


see also:
<http://msdn2.microsoft .com/en-us/library/system.xml.xmlt extwriter.forma tting>

--
Pascal Schmitt
Nov 12 '05 #2
Perfect, thank you so much!
"Pascal Schmitt" <ne*******@cebr a.nu> wrote in message
news:Oi******** *****@TK2MSFTNG P12.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_ optionsXmlFileP ath, false);
XmlSerializer xmlSerializer = new XmlSerializer(t ypeof(Options)) ;
XmlTextWriter xmlTextWriter = new XmlTextWriter(s w);

xmlTextWriter.F ormatting = Formatting.Inde nted

xmlSerializer.S erialize(xmlTex tWriter, this);
xmlTextWriter.C lose();
</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
4201
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 of the old pathname, and closing tags are left on the end resulting in an invalid XML file. XmlSerializer.Deserialize gives a System.InvalidOperationException with additional information: Error in the XML document. My default file for example...
5
5430
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 create duplicate XML representations of the shared object, but instead use IDREFs to refer to the shared object. The XML I'm trying to produce is as follows (where "href" is an IDREF): <?xml version="1.0" encoding="utf-8"?> <MyRootClass...
8
3571
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 initially tested my design by building a collection in code and then serializing it to/from an XML file, which worked fine. However, I have hit a brick wall trying to restore the data from SQL Server. I originally had my collection and object
0
2029
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 class with attribute XmlSerializable. This "second level" class named "SecondClass" has an attribute of type XmlSerializable, a public property of type ArrayList, with attribute XmlElement to describe the contents of the ArrayList, the contents...
0
9723
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 second Serialize work namespace SerializeTes public class Class args Test _test = new Test() _test.TestAnimal()
3
17733
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. What I would like to do is use MemoryStream to do this instead of writing to the harddrive, but I am lost in the readers, writers etc. Can someone show me how to to this using a memory stream. thanks
3
4519
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 XmlText. In my main class, i have created an arraylist which contains a collection of this class FormField. Basically its: public void Add( string sName, string sValue )
3
10414
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 the road. It would be awesome somebody could answer this, sadly most of my questions don't get answered. Regards,
4
6871
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"); xSer.Serialize(sw, theData); sw.Close(); I need to add a style reference within the file that looks like this: <?xml-stylesheet type="text/xsl" href="MyStyle.xsl"?>
0
10448
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10217
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10167
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7544
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6784
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5566
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2922
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.