XML serialization

M

muz dogru

I am serializing an object with the following method:

XmlDocument xmlDocument = new XmlDocument();
XmlSerializer xmlSerializer = new XmlSerializer(o.GetType());
StringWriter stringWriter = new StringWriter();
xmlSerializer.Serialize(stringWriter, o);
xmlDocument.LoadXml(stringWriter.ToString());

This returns an XML like:

<?xml version="1.0" encoding="utf-16"?>...

How can I change the encoding?

Thanks.
 
G

Guest

hi.....

you can try something like this.

public class StringWriterWithEncoding : StringWriter
{
Encoding encoding;

public StringWriterWithEncoding (Encoding encoding)
{
this.encoding = encoding;
}

public override Encoding Encoding
{
get { return encoding; }
}
}

hope this helps,
Kannan.V [MCAD.net]
http://kannanv.blogspot.com
 

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