I need to print arbitrary SimpleXML objects in a specific manner, with special handling of attribute nodes.
The problem is that SimpleXML elements and attri
You need SimpleXMLElement::attributes:
function xml_out($el) {
$name = $el->getName();
echo '<'. $name;
if (count($el->attributes())) {
foreach ($el->attributes() as $a=>$v) {
echo ' '. ((string)$a) . '="' . htmlspecialchars((string)$v) . '"';
}
}
echo '>'. (string)$el;
if (count($el->children())) {
foreach($el->children() as $c) {
xml_out($c);
}
}
echo ''. $name . '>';
}
May need a bit of tweaking.