Hey,
I am trying to get XML node values from an XML file.
Everything seems to work, no errors, but no nodes are returned by tagname.
You can enter the URL and you’ll see that the XML nodes do exist.
function load_currency_xml($currency){
// Load currency in XML format
$ret_array = Array();
$doc = new DOMDocument('1.0','utf-8');
$doc->load("http://www.bankisrael.gov.il/heb.shearim/currency.php?curr={$currency}"); //FIXME: tags dont get loaded
// get file
$doc->formatOutput = true;
// Nicely format the file
$ret_array['cur_code'] = $doc->getElementsByTagName("currencycode")->item(0);
$ret_array['rate'] = $doc->getElementsByTagName("rate")->item(0);
return $ret_array;
}
$dollar = load_currency_xml("01");
echo $dollar['cur_code']->textContent;
echo $dollar['rate']->textContent;
XML node names are case sensitive so you need to specify them with their proper case. For the XML you want to get, that means CURRENCYCODE and RATE rather than the lower-case names you’re currently using.
@Greg Winiarski:
I got in the habit of working with the DOM. The first task I had to accomplish with XML forced me to use the DOM, plus I do a lot of DOM manipulation with JavaScript, so that seems the right way to do it for me.