Save xml as UTF8

Asked

Viewed 101 times

1

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

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

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);
}

inserir a descrição da imagem aqui

1 answer

0


For this just use one of the builders of the 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 whether to overwrite the existing file (false).

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.