Search code examples
c#xmlencodingutf-8xmldocument

How Can I Encode My New Xml Document?


I have a string with a XML text and i want to save it like XML. I encoded string (to "utf-8") but when i want to make XML from that - my cyrillic symbols in Value don't displayed right . What i need to do to encode my XML document ?

part of my xml :

 <rev:Code>Мои данные</rev:Code>

my code:

 string send = Encoding.GetEncoding("utf8").GetString(Encoding.GetEncoding("utf-8").GetBytes(send)); 
XmlDocument docsec = new XmlDocument();
 docsec.LoadXml(send);
docsec.Save("C:\\XmlNEW.xml");

Original text :Мои данные

I see it after creating XML :Мои данные


Solution

  • Problem was in Save Method because it use xml encoding, i take my answer from this : Answer

    XmlDocument docsec = new XmlDocument();
    docsec.LoadXml(send);
    using (TextWriter writer = new StreamWriter("C:\XmlNEW.xml", false, Encoding.UTF8))
        docsec.Save(writer);