PHP XMLReader, get the version and encoding

andybush

New Member
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. However, I can't figure out how to get the version, encoding and standalone flags from the XML preamble. The start of my test XML file looks like this: \[code\]<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE fakedoctype SYSTEM "fake_doc_type.dtd"> <!-- This is a comment, it's here to try and get the parser to break in some way --> <root attribute="value" otherattribute="othervalue">\[/code\]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\]<?xml ... ?>\[/code\]. The first thing I'm able to access is the fake DOCTYPE.My testing code is as follows: \[code\]$a = new XMLReader ();var_dump ($a -> open ('/path/to/test/file.xml')) // truevar_dump ($a -> nodeType); // 0var_dump ($a -> name); // ""var_dump ($a -> readOuterXML ()); // ''var_dump ($a -> read ()); // truevar_dump ($a -> nodeType); // 10var_dump ($a -> readOuterXML ()); // <!DOCTYPE fakedoctype SYSTEM "fake_doc_type.dtd">\[/code\]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. 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?
 
Back
Top