New line and Tabs in XML files?

  • Thread starter Thread starter Ole
  • Start date Start date
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
 
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
 
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
 
Back
Top