I have been using PHP's simple XML function to work with an XML file.
The below code works fine for a simple XML hierarchy:
$xml = simplexml_load_file("test.xml");
echo $xml->getName() . "<br />";
foreach($xml->children() as $child)
{
echo $child->getName() . ": " . $child . "<br />";
}
This assumes the structure of the XML document is as follows:
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
However, if I had a more complex structure within my XML document - the contents simply is not output. A more complex XML example is shown below:
<note>
<noteproperties>
<notetype>
TEST
</notetype>
</noteproperties>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
I need to process XML files that have an indefinite depth - can anyone suggest a method?
That's because you need to go another level down in
<noteproperties>
Check this out, example from SimpleXMLElement::children: