[ create a new paste ] login | about

Link: http://codepad.org/BehmuqJ1    [ raw code | output | fork ]

PHP, pasted on Nov 6:
<?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);


Output:
1
2
3
4
5
6
7
8
9

	

L1-------------------------------
foo = bar
-----:
---L2----------------------------
baz = boo
-----:


Create a new paste based on this one


Comments: