I'm making a script, that reads through the passed XML file and displays the source code. I've got it almost done, but the item attributes .. I can't find a way to catch them. Here's the code:
$xml = simplexml_load_file("path/to/file.xml");
showTree($xml->children(), 0);
function showTree($value, $i) {
if($value == '') {
foreach($value as $name2 => $value2) {
echo str_repeat('--', $i)." <$name2> \n";
showTree($value2, ($i+1));
echo str_repeat('--', $i)." </$name2> \n";
}
} else { echo str_repeat('--', $i)." ".trim($value)."\n"; }
} // end: function
As I said, it works fine, but doesn't display the attributes, for example:
<item id=2>Item</item>
returns only the:
<item>Item</item>
Thanks for any responses, Mike.