title: PHP XMLReader, get the version and encoding
body: <p>I'm currently rewriting a PHP class that tried to split an XML file into smaller chunks to use XMLReader and XMLWriter instead of the current basic filesystem and regex approach.  </p>
  
  <p>However, I can't figure out how to get the version, encoding and standalone flags from the XML preamble.  </p>
  
  <p>The start of my test XML file looks like this: </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE fakedoctype SYSTEM "fake_doc_type.dtd"&gt;
  
   &lt;!--
   This is a comment, it's here to try and get the parser to break in some way
   --&gt; 
  
  &lt;root attribute="value" otherattribute="othervalue"&gt;
  </code></pre>
  
  <p>I can open it okay with the reader and move through the document with read(), next() etc, but I just can't seem to get whatever's in <code>&lt;?xml ... ?&gt;</code>.  The first thing I'm able to access is the fake DOCTYPE.</p>
  
  <p>My testing code is as follows: </p>
  
  <pre><code>$a = new XMLReader ();
  var_dump ($a -&gt; open ('/path/to/test/file.xml')) // true
  var_dump ($a -&gt; nodeType); // 0
  var_dump ($a -&gt; name); // ""
  var_dump ($a -&gt; readOuterXML ()); // ''
  var_dump ($a -&gt; read ()); // true
  var_dump ($a -&gt; nodeType); // 10
  var_dump ($a -&gt; readOuterXML ()); // &lt;!DOCTYPE fakedoctype SYSTEM "fake_doc_type.dtd"&gt;
  </code></pre>
  
  <p>Of course I could just always assume XML 1.0, encoding UTF8 and standalone = yes, but for the sake of correctness I'd really rather be able to grab what the values in my source feed are and use them when generating the split files.  </p>
  
  <p>The documentation on XMLReader and XMLwriter seems to be very poor, so there's every chance I've just missed something in the docs.  Does anyone know what to do in this case?  </p>