I have the following SimpleXMLElement Object http://pastebin.com/qEP0UUPJ
I can query it using xpath $xaugbp = $xml->xpath("/query/results/rate"); but this just narrows down the search:
I wish to access the following object:
[0] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => XAUGBP ) [Name] => XAU to GBP [Rate] => 1030.5784 [Date] => 7/27/2012 [Time] => 5:55pm [Ask] => 1027.5662 [Bid] => 1033.5896 I can get that particular object using
$ob = $xmlObject->xpath("//query/results/rate[contains(@id, 'XAUGBP')]"); I can get 'Ask' by using
$ob = $xmlObject->xpath("//query/results/rate[contains(@id, 'XAUGBP')]/Ask"); But how do I turn that object into a variable. e.g. so that I can do calculations on it?
Is xpath the only way of doing this? Is there a better / more efficient / quicker way? Is it possible to convert this to an associative array for easy access?