I have tried to parse an XML response that does not work. In the API docs it says that it is a XML based protocol: SRU. Wont this XML parsing code work then? Or is it some error in the code?
code:
$xmldoc = new DOMDocument();
$xmldoc->load('http://api.site.com/sru/query=' . $_GET['q']);
print_r($xmldoc);
$xpathvar = new Domxpath($xmldoc);
$queryResult = $xpathvar->query('//datafield[@tag="020"]/subfield[$code="a"]');
foreach ($queryResult as $result) {
echo $result->textContent;
print_r($result);
}
xml structure:
<searchRetrieveResponse>
<numberOfRecords>1</numberOfRecords>
<datafield tag="020" ind1=" " ind2=" ">
<subfield code="a">xyz</subfield>
</datafield>
...
</searchRetrieveResponse>