title: Getting SimpleXMLElement to include the encoding in output
body: <p>This:</p>
  
  <pre><code>$XML = new SimpleXMLElement("&lt;foo /&gt;");
  echo($XML-&gt;asXML());
  </code></pre>
  
  <p>...outputs this:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;foo/&gt;
  </code></pre>
  
  <p>But I want it to output the encoding, too:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;foo/&gt;
  </code></pre>
  
  <p>Is there some way to tell SimpleXMLElement to include the encoding attribute of the &lt;?xml?> tag? Aside from doing this:</p>
  
  <pre><code>$XML = new SimpleXMLElement("&lt;?xml version='1.0' encoding='utf-8'?&gt;&lt;foo /&gt;");
  echo($XML-&gt;asXML());
  </code></pre>
  
  <p>Which works, but it's annoying to have to manually specify the version and encoding.</p>
  
  <p>Assume for the purposes of this question that I cannot use DOMDocument instead.</p>