<?php
function compact_($node,$indent){
if ($node->nodeType==XML_ELEMENT_NODE) {
print $node->nodeName."[";
$indent.=str_repeat(' ',strlen($node->nodeName)+1);
$first=true;
foreach ($node->attributes as $attrName => $attrValue) {
if(!$first)print "\n$indent";
print "@".$attrName."[".$attrValue->value."]";
$first=false;
}
foreach ($node->childNodes as $child)
if($child->nodeType==XML_ELEMENT_NODE or
strlen($child->textContent)>0 ){
if(!$first)print "\n$indent";
compact_($child,$indent);
$first=false;
}
print "]";
} else if ($node->nodeType==XML_TEXT_NODE)
print preg_replace("/ *\n? +/"," ",trim($node->textContent));
}
$dom = new DomDocument();
$dom->preserveWhiteSpace = false;
$dom->substituteEntities = true;
$dom->load("php://stdin");
compact_($dom->documentElement,"");
print "\n";
?>