I have a function which uses simplexml to return the first level of nodes in an XML file and write it into an unordered list:
function printAssetMap() {
$xml = simplexml_load_file(X_ASSETS);
$assets = $xml->asset;
$html = <ul> ."
";
foreach ($assets as $asset) {
$html .= <li id="asset .$asset->asset_assetid. "><ins> </ins><a href="#"> .$asset->asset_name. [ .$asset->asset_assetid. ]</a></li> ."
";
}//end foreach
$html .= </ul> ."
";
return $html;
}// printAssetMap()
XML I am using, that has nested nodes:
<?xml version="1.0"?>
<assets>
<asset>
<asset_name>Home</asset_name>
<asset_url>/home</asset_url>
<asset_assetid>1</asset_assetid>
</asset>
<asset>
<asset_name>Projects</asset_name>
<asset_url>/projects</asset_url>
<asset_assetid>2</asset_assetid>
<asset>
<asset_name>Portfolio</asset_name>
<asset_url>/projects/portfolio</asset_url>
<asset_assetid>3</asset_assetid>
</asset>
<asset>
<asset_name>Current Jobs</asset_name>
<asset_url>/projects/current-jobs</asset_url>
<asset_assetid>4</asset_assetid>
</asset>
</asset>
</assets>
Now, I am starting to add child nodes of the nodes that I am currently returning. Is there a way to loop through ALL levels of child nodes in an xml file, even if I don t know how many levels there are, and add those to my list?