New line and Tabs in XML files?

O

Ole

Hi, I have a strange problem - when writing to a file from a Full framework
application I get the normal XML format but when I write to a file in a
Compact Framework application using the exact same code I get one single
unwrapped linin XML.?? I'm using XML serialization like this:

TestObject test = new TestObject();
XmlSerializer ser = new XmlSerializer(test.GetType());

StreamWriter file = new StreamWriter(@"C:\test.xml");
ser.Serialize(file, test);
file.Flush();
file.Close();

What can I do correct that problem?

Thanks
Ole
 
G

Guest

Try this:


System.Xml.Serialization.XmlSerializer ser = new
System.Xml.Serialization.XmlSerializer(test.GetType());

System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\test.xml");
System.Xml.XmlTextWriter xtr = new System.Xml.XmlTextWriter(file);
xtr.Formatting = System.Xml.Formatting.Indented;
ser.Serialize(xtr, test);
file.Flush();
file.Close();

HTH

Ciaran O'Donnell
 
O

Ole

Thanks Ciaran!


Ciaran O''Donnell said:
Try this:


System.Xml.Serialization.XmlSerializer ser = new
System.Xml.Serialization.XmlSerializer(test.GetType());

System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\test.xml");
System.Xml.XmlTextWriter xtr = new System.Xml.XmlTextWriter(file);
xtr.Formatting = System.Xml.Formatting.Indented;
ser.Serialize(xtr, test);
file.Flush();
file.Close();

HTH

Ciaran O'Donnell
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top