<?php
function dpm($string) {
echo $string ."\n";
}
function recurse($xml, $maxLevel = -1, $level = 0) {
if ($maxLevel != -1 && $level > $maxLevel) {
return;
}
if ($level == 0) {
dpm($xml);
}
$string = '---------------------------------';
$pos = $level * 3;
$l = 'L'. ($level+1);
$string = substr_replace($string, $l, $pos, strlen($l));
foreach ($xml->section as $section) {
dpm($string);
foreach ($section->attributes() as $a=>$b) {
dpm($a .' = '. $b);
}
dpm('-----:');
recurse($section, $maxLevel, $level+1);
}
}
$xml = simplexml_load_string(<<<EOD
<?xml version="1.0"?>
<section>
<section foo="bar">
<section baz="boo">
<section lorem="ipsum">
</section>
</section>
</section>
</section>
EOD
);
recurse($xml, 1);