<?php
function tag($tag,$body,$attrs=""){
   return "<$tag".($attrs?" ":"")."$attrs>$body</$tag>";
}

function compact_($node){
    if ($node->nodeType==XML_ELEMENT_NODE) {
        $res="";
        $attrs="";
        foreach ($node->attributes as $key => $value)
            $attrs.=" $key='$value->value'";
        $res.=tag("b",$node->nodeName)." ".$attrs;
        $children = $node->childNodes;
        if($children->length>1){
            $cs="";
            foreach($children as $child)
                $cs.=compact_($child);
            $res.=tag("ul",$cs);
        } else 
            $res.=compact_($children->item(0));
        return tag("li",$res);
    } else if ($node->nodeType==XML_TEXT_NODE){
        return preg_replace("/ *\n? +/"," ",trim($node->nodeValue));
    }
}

$dom = new DomDocument();
$dom->preserveWhiteSpace = false;
$dom->substituteEntities = true;
$file = $_GET['file'];
$dom->load($file?$file:"php://stdin");
?>
<html xmlns="http://www.w3.org/1999/xhtml">
     <head>
         <title>HTML compaction of "<?php print $_GET['file']?>"</title>
     </head>
     <body>
         <ul>
             <?php print compact_($dom->documentElement,"")?>
         </ul>
     </body>
</html>