XML : Xml character encoding with UTF format

I am serializing c# object to Xml using below code.

  public class Utf8StringWriter : StringWriter          {              public override Encoding Encoding { get { return Encoding.UTF8; } }          }    public string SerializeDataWithUTF8Encoding<T>(T data)          {              XmlSerializer serializer = new XmlSerializer(typeof(T));              StringWriter sw = new Utf8StringWriter();              serializer.Serialize(sw, data);              var xmlString = sw.ToString();              return xmlString;          }    

Using this code, i am serializing below object with static value as mentioned below.

  public class Test  {   string Description = "This is the charge in advance for your %quantity% Line isolating unit No. 1A at &#xA3;%quantity rate% per unit per month";  }    Test obj = new Test();    //calling above function  SerializeDataWithUTF8Encoding(obj)    

but in the xml generated above, i am getting description as

"This is the charge in advance for your %quantity% Line isolating unit No. 1A at £%quantity rate% per unit per month".

  //putting space here to stop encoding again    so here " &#xA3 ; " is encoded as '£'.     

How can i stop this encoding ? I wan to keep "£" as is in the Xml.

I have tried several options but not getting much help.

Thanks a lot in Advance.

No comments:

Post a Comment