I have a piece of code that calls an external file and returns the results from a database as an xml output as below:
$file = 'http://computers.mysite.co.uk/vrm.xml?apikey=**********&vid=Check&vrm='.$reg;
if(!$xml = simplexml_load_file($file))
exit('Failed to open '.$file);
print_r($id);
This returns the results like this:
<computers sid="1234">
<computer id="253406" name="computer name)" model_group="Microsofth" start_year="2005" end_year="2009">
<system id="969623" capacity="3.4"/>
<developer id="64" name="intel"/>
<machine id="8" name="P" etype="P"/>
<products>
<product id="9" name="computer screwdriver" datasheet="" packshot=""/>
<product id="16" name="Screwdriver Crosshead" datasheet="" packshot=""/>
</products>
</computer>
</computers>
Instead of showing the results like this, is it possible to return them or change them into basic php variables such as:
$compputer_sid
$computer_id
$system_id
and so on.
UPDATE: Doh, you’re already using SimpleXML.
you can access nodes with syntax like this:
Try: