Xml Serialization and Xml Encoding

G

Guest

Using Xml Serialization to serialize an object, how can i take control over
the finall Xml Encoding?

I mean, when i serialize an object, i always get something like that

== == ==
<?xml version="1.0" encoding="utf-8"?>
<xxxxxx>
.. . . .
</xxxxxx>
== == ==

and i need this (xml enconding = iso-8859-1)

== == ==
<?xml version="1.0" encoding="iso-8859-1"?>
<xxxxxx>
.. . . .
</xxxxxx>
== == ==

thanks
 
M

Martin Honnen

Ricardo said:
Using Xml Serialization to serialize an object, how can i take control over
the finall Xml Encoding?
and i need this (xml enconding = iso-8859-1)

You serialize to an XmlTextWriter, don't you? There you can choose the
encoding when you create the XmlTextWriter
<http://msdn.microsoft.com/library/d...rlrfSystemXmlXmlTextWriterClassctorTopic3.asp>
e.g.
XmlTextWriter xmlWriter = new XmlTextWriter("object.xml",
System.Text.Encoding.GetEncoding("ISO-8859-1"));

XmlSerializer serializer = new XmlSerializer(typeof(Whatever));
serializer.Serialize(xmlWriter, whatever);
 

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