<?php
function compact_($sxelem,$indent){
print $sxelem->getName()."[";
$indent.=str_repeat(' ',strlen($sxelem->getName())+1);
$first=true;
foreach ($sxelem->attributes() as $attname => $attvalue) {
if(!$first)print "\n$indent";
print "@{$attname}[$attvalue]";
$first=false;
}
$text = trim($sxelem);
if(strlen($text)){
print preg_replace("/ *\n? +/"," ",$text);
$first=false;
}
$children = $sxelem->children();
foreach ($children as $child){
if(!$first)print "\n$indent";
compact_($child,$indent);
$first=false;
}
print "]";
}
$dom = simplexml_load_file('php://stdin');
compact_($dom,"");
print "\n";
?>