title: SimpleXML outputs unicode in a strange way
body: <p>I use simpleXML to process xml file. It has Cyrillic characters. I also use <code>dom_import_simplexml</code>, <code>importNode</code> and <code>appendChild</code> to copy trees from file to file and place to place.
  At the end of processing I do <code>print_r</code> of resulting <code>simpleXmlElement</code> and everything is ok. But I also do <code>asXml('outputfile.xml')</code> and something strange is going on: all cyrillic characters that was not wrapped with <code>CDATA</code> (some tags bodies and all attributes) change to their unicode code.</p>
  
  <p>For example, the output of <code>print_r</code> (just a fragment):  </p>
  
  <pre><code>SimpleXMLElement Object ( [@attributes] =&gt; Array 
               ( [NAME] =&gt; Государственный аппарат и     механизм 
                 [COSTYES] =&gt; 3.89983579639 [COSTNO] =&gt; 0 
                 [ID] =&gt; 9 )
             [COMMENTYES] =&gt; Вы совершенно         правы. 
            [COMMENTNO] =&gt; Нет, Вы ошиблись. ) ) )
  </code></pre>
  
  <p>But in file that <code>asXml</code> generates, i get something like this:  </p>
  
  <pre><code>&lt;QUEST NAME="&amp;#x422;&amp;#x435;&amp;#x43E;&amp;#x440;&amp;#x438;&amp;#x44F;#x434;&amp;#x432;&amp;#x443;&amp;#x445;&amp;#x43C;&amp;#x435;&amp;#x447;&amp;#x435;&amp;#x439;"     
      style="educ" ID="1"&gt;
    &lt;DESC&gt;&lt;![CDATA[Теория происхождения государства, известная как теория "двух мечей" [2, с.40], 
      представляет из себя...
    ]]&gt;&lt;/DESC&gt;`
  </code></pre>
  
  <p>I set utf-8 locale everywhere it's possible, googled every combination of words "simplexml, unicode, cyrillic, asXml, etc" but nothing worked.</p>
  
  <p><strong>UPD</strong> Looks like some function used does <code>htmlentities()</code>. So, thanks to <a href="https://stackoverflow.com/users/2088851/voitcus">voitcus</a>, the solution is to use <code>html_entity_decode()</code> as adviced <a href="http://www.php.net/manual/en/simplexmlelement.asxml.php#107137" rel="nofollow noreferrer" title="comment on man page for asXml()">here</a>.</p>