I am trying to import a XML file via API into my php script which then will parse said XML file and extract a string. Ive searched across the webspace for an answer, and though I have found a ton of resources I still cannot get this script to work.
The XML file that I am loading will look something like this
<api version="2">
<currentTime>2012-07-28</currentTime>
<result>
<rowset name="accounts" key="accountID" columns="accountID,accountKey,balance">
<row accountID="555555555" accountKey="6666" balance="7777777777.23"/>
</rowset>
</result>
<cachedUntil>2012-07-28</cachedUntil>
</api>
I am trying to get my php script to fetch the value of the attribute balance.
This is the code that I have put together so far:
<?php
$apiurl = "api.some-arbitrary-api-site.com;
$xml = simplexml_load_file($apiurl);
print_r($xml);
$balance = $xml->balance;
print_r($balance);
?>
This returns:
SimpleXMLElement Object ( )
Also following some other web tutorials I have tried this change
$balance = $xml->row->attributes()->balance;
print_r($balance);
Which spits out
Warning: main() [function.main]: Node no longer exists in C:\xampp\htdocs\EVE\progress\import.php on line 22
Warning: main() [function.main]: Node no longer exists in C:\xampp\htdocs\EVE\progress\import.php on line 22
What am I doing wrong? The end result is for the page to load this API and fetch the balance once every two days and store the data to be used in a chart rendered using highchart.
Any help will be appreciated!
Thanks
Musa answered the question
I was being an idiot and didnt check the xml over again when typing in the path.
Thanks