P
P
Pavel Chuev2018-03-22 00:15:04
PHP
Pavel Chuev, 2018-03-22 00:15:04

How to pull element from xml?

I'm trying to extract the date from the xml of the Central Bank of the Russian Federation.
Everything is available at the link itself: TYK

<?
$xml = new DOMDocument();
$date = @$xml->load('http://www.cbr.ru/scripts/XML_daily.asp?date_req=' . date('d/m/Y'));
$root = $date->documentElement;
$valcurs = $root->getElementsByTagName('ValCurs');
echo $valcurs->item(0)->getAttribute('Date');
?>

I get the following->
Fatal error: Uncaught Error: Call to a member function getElementsByTagName() on null in C:\Users\Decay\Desktop\public_html\test\load.php:12 Stack trace: #0 {main} thrown in C:\Users\Decay\Desktop\public_html\test\load.php on line 12

Where is the mistake?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question