I fetch data from an XML feed using cURL. I need to get a specific value from the XML.
I need the text: Gymnázium Christiana Dopplera (<D:Nazev>
)
I've tried using DOMDocument
, but I get a "Fatal error".
What am I doing wrong?
if ($curl = curl_init("http://wwwinfo.mfcr.cz/cgi-bin/ares/darv_sko.cgi?ico=61385701")) {
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$content = curl_exec($curl);
curl_close($curl);
}
$dom = new DOMDocument();
$dom = loadXML($content);
echo $dom->getElementsByTagName("Nazev");
Fatal error: Call to undefined function loadXML() in C:\www\pokusy\ares\index.php on line 13
SimpleXML will convert the entire XML document into a object and you can go from there.
You can use DOMDocument
, as you've stated, in the following way:
$dom = new DOMDocument();
$dom->loadXML($content);
foreach ($dom->getElementsByTagName("Nazev") as $item)
echo 'Value: '.$item->nodeValue.'<br />'.PHP_EOL;