My Q is: what is the simplest way, in PHP, to parse the XML returned by a SRU request?
For instance, look at the following URL in a browser:
http://explor.bcu.ac.uk/IntraLibrary-SRU?operation=searchRetrieve&query=gaelic&version=1.1
This query to a public repository returns a well-formed XML document (it validates) conforming to the SRU standard, in this case returning two records. I've played with various permutations of simplexml_load_string() and methods of SimpleXMLElement(), running print_r and var_dump, and never get anything usable. For example:
$url = "http://explor.bcu.ac.uk/IntraLibrary-SRU?operation=searchRetrieve&query=gaelic&version=1.1";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL,$url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$file_contents = curl_exec($ch);
$xml = new SimpleXMLElement($file_contents);
print_r($xml);
This just outputs:
SimpleXMLElement Object ( )
If I replace the print_r with:
echo $xml -> asXML();
I at least get the XML data as one long string.
What I'd like to see in print_r is an object/array with all XML nodes displayed, so that I can then see what all the nodes and children are in object notation.
An added wrinkle to this is that the nodes in the returned XML have names such as:
<SRW:recordSchema>dc</SRW:recordSchema>
so I can't use code such as:
if ($xml -> SRW:recordSchema -> children()
as that'll throw a syntax error over the semicolon.
I'm no expert on XML. I understand basic structure, and I've parsed simple XML docs (such as in the PHP manual "Basic SimpleXML examples"), but terms like xPath and namespace go over my head. I've had a look at:
How can I parse a XML document retrieved from SRU?
http://us3.php.net/SimpleXMLElement
and have Googled for "php parse sru xml". Before I get lost in XML, I'd be grateful if someone could just point me in the right direction.