How can I achieve that.
The current Code is
[code]
IDA idaEntity = new IDA ();
idaEntity.First_Name ="abc";
idaEntity.Last_Name ="def";
idaEntity.Address_Line1 ="123456";
idaEntity.Address_Line2 ="";
idaEntity.City ="abcdef";
idaEntity.State ="AA";
idaEntity.Zip_Code ="12345";
idaEntity.Home_Phone ="1234567890";
idaEntity.Work_Phone ="";
idaEntity.SSN ="123456789";
idaEntity.Customer_ID = "1234567";
idaEntity.Order_ID= "98765432";
StringBuilder sb = new StringBuilder ();
XmlSerializer addSerializer = new XmlSerializer(typeof(IDA));
XmlTextWriter writer = new XmlTextWriter( new StringWriter (sb) );
writer.Formatting = Formatting.None;
addSerializer.Serialize(writer, idaEntity);
Console.WriteLine(sb);
[/code]
The output I am getting is
[OUTPUT]
<?xml version="1.0" encoding="utf-16"?><IDA
xmlns:xsd="http://www.w3.org/2001/XM
LSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Customer_ID>50027961</Customer_ID><Order_ID>50027317</Order_ID><First_Name>abc
</First_Name><Last_Name>def</Last_Name><Address_Line1>123456</Address_Line1><Ad
dress_Line2
/><City>abcdef</City><State>AA</State><Zip_Code>12345</Zip_Code><
SSN>123456789</SSN><Home_Phone>1234567890</Home_Phone><Work_Phone
/></IDA>
[/OUTPUT]
How can I get encoding utf-8 instead of 16.
Thanks !
Serialize to a file or a stream, not to a string writer as a string is
always (internally) UTF-16 encoded.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
However, you can still make a StringWriter expose its encoding as UTF-8
by overriding its properties.
It so happens I have a class which does exactly that in my utility
library :)
See http://www.pobox.com/~skeet/csharp/miscutil
and look at MiscUtil.IO.StringWriterWithEncoding
--
Jon Skeet - <sk...@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
HTH,
Sam
------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
On 5 Dec 2006 06:19:52 -0800, "piku" <puj...@gmail.com> wrote:
>
> I am trying to generate XML file with UTF encoding 8 ,
> But after serliazation the xml is generated as
><?xml version=\"1.0\" encoding=\"utf-16\"?>
> I want UTF encoding 8 .
>