I have a basic XML file that I load in my PHP using
$xml = simplexml_load_file("file.xml");
I want to be able to access my data using syntax something similar to:
$xml[0]['from'];
$xml['note']['from'];
$xml['from']['email'];
I know I can access the data using this:
foreach($xml->children() as $child) {
echo $child->getName() . ": " . $child . "<br />";
}
However, this is NOT a preferred method, and I would like to use syntax similar to multidimensional arrays.
Using APIs from many different websites, this is generally how I would access XML, however, I can't seem to do it with my own using simplexml_load_file("file.xml");
I know this is very simple but is there something I'm missing? Please help! Thanks in advance
XML File:
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Tove</to>
<from>
<name>Jani</name>
<email>[email protected]</email>
</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>