Save xml as UTF8

1

I'm consuming a Webservice, where return is an XML.

Save The XML in a directory to another system read. how do I save this XML as UTF-8? The other system read the content but the special character is unconfigured.

WSHP.XMLServer ws = new WSHP.XMLServer();
var xml = GerarXMLConsulta();
string login = "12000";
string senha = "4329";
var ret = ws.getResultado(login, senha, xml);

using (StreamWriter myWriter = new StreamWriter("D:\downloads\Retorno.xml"))
{
    myWriter.Write(ret);
}

    
asked by anonymous 09.10.2018 / 13:30

1 answer

0

To do this, just use one of the constructors of StreamWriter :

using (StreamWriter myWriter = new StreamWriter("D:\downloads\Retorno.xml", false, Encoding.UTF8))
{
    myWriter.Write(ret);
}

In the 2nd parameter we indicate if we want the content to be added to the file ( true ) or if it should overlap the existing file ( false ).

In the 3rd parameter we define the Encoding , which in this case is UTF-8 .

    
09.10.2018 / 15:47