title: Downloading right xml encoding with JSF
body: <p>The issue is the following.
  There is xml file, created by DocumentBuilderFactory.
  Then it is necessary to download this file with the browser.</p>
  
  <p>The code is the following:</p>
  
  <pre><code>StringWriter sw = new StringWriter();
  TransformerFactory tf = TransformerFactory.newInstance();
  Transformer transformer = tf.newTransformer();
  transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
  transformer.setOutputProperty(OutputKeys.METHOD, "xml");
  transformer.setOutputProperty(OutputKeys.INDENT, "yes");
  transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
  
  transformer.transform(new DOMSource(doc), new StreamResult(sw));
  
  String xml = sw.toString();//returns the whole XML but in String format.
  
  
  HttpServletResponse response = (HttpServletResponse) 
  FacesContext.getCurrentInstance().getExternalContext().getResponse();
  response.setContentType("text/xml");
  response.setHeader("Content-Disposition", "attachment;filename=export.xml");
  ServletOutputStream out = response.getOutputStream();
  out.write(xml.getBytes());
  out.flush();
  </code></pre>
  
  <p>When it is exported, I have the problem with non-Latin symbols. As an example, Cyrillic word is exported as \xED\xEE\xE2\ symbols. How to correct this?
  The other part of file is exported correctly.</p>