Parsing XML with the PHP XMLReader
Posted
by coffeecoder
on Stack Overflow
See other posts from Stack Overflow
or by coffeecoder
Published on 2010-03-17T15:05:45Z
Indexed on
2010/03/17
15:51 UTC
Read the original article
Hit count: 586
Hi Guys,
I am writing program that reads in some XML from the $_POST variable and then parses using the PHP XMLReader and the data extracted input into a database. I am using the XMLReader as the XML supplied will more than likely be too big to place into memory.
However I am having some issues, my XML and basic code as are follows:
'<?xml version="1.0"?>
<data_root>
<data>
<info>value</info>
</data>
<action>value</action>
</data_root>'
$request = $_REQUEST['xml'];
$reader = new XMLReader();
$reader->XML($request);
while($reader->read()){
//processing code
}
$reader->close()
My problem is that the code will work perfectly if the XML being passed does not have the <?xml version="1.0"?>
line, but if i include it, and it will be included when the application goes into a live production environment, the $reader->read()
code for the while loop does not work and the XML is not parsed within the while loop.
Has anyone seen similar behaviour before or knows why this could be happening?
Thanks in advance.
© Stack Overflow or respective owner