function formatxml($el, $depth) { $ind = $depth * 10; echo "<div style='margin-left:{$ind};'>"; if ($el->nodeType == 1) { if ($el->childNodes->length == 0) { echo "<" . $el->tagName; attrib($el); echo "/>"; } else { echo "<" . $el->tagName; attrib($el); echo "><br/>"; foreach ($el->childNodes as $child) { formatxml($child, $depth + 1); } echo "</" . $el->tagName . ">"; } } if ($el->nodeType == 3) { echo "<span style='color:red'>" . $el->nodeValue . "</span><br/>"; } echo "</div>"; }
function formatxml($el, $depth, $namespaceuri) { $ns = ""; // echo $el->lookupnamespaceURI(NULL); if (!($namespaceuri == $el->lookupnamespaceURI(NULL))) { $ns = "<span style='color:purple'> xmlns</span>=<span style='color:red'> '" . $el->lookupnamespaceURI(NULL) . "'</span> "; } $namespaceuri = $el->lookupnamespaceURI(NULL); $ind = $depth * 10; echo "<div style='margin-left:{$ind};' >"; if ($el->nodeType == 1) { if ($el->childNodes->length == 0) { echo "<" . $el->tagName; attrib($el); echo "/>"; } else { echo "<" . $el->tagName; echo $ns; attrib($el); echo "><br/>"; foreach ($el->childNodes as $child) { formatxml($child, $depth + 1, $namespaceuri); } echo "</" . $el->tagName . ">"; } } if ($el->nodeType == 3) { echo "<span style='color:red'>" . $el->nodeValue . "</span><br/>"; } echo "</div>"; }