1<?PHP 2$xmlstr = "<?xml version='1.0' standalone='yes'?> 3<!DOCTYPE chapter SYSTEM '/share/sgml/Norman_Walsh/db3xml10/db3xml10.dtd' 4[ <!ENTITY sp \"spanish\"> 5]> 6<!-- lsfj --> 7<chapter language='en'><title language='en'>Title</title> 8<para language='ge'> 9&sp; 10<!-- comment --> 11<informaltable language='&sp;kkk'> 12<tgroup cols='3'> 13<tbody> 14<row><entry>a1</entry><entry morerows='1'>b1</entry><entry>c1</entry></row> 15<row><entry>a2</entry><entry>c2</entry></row> 16<row><entry>a3</entry><entry>b3</entry><entry>c3</entry></row> 17</tbody> 18</tgroup> 19</informaltable> 20</para> 21</chapter> "; 22 23function print_node($node) 24{ 25 print "Node Name: " . $node->nodeName; 26 print "\nNode Type: " . $node->nodeType; 27 if ($node->nodeType != 3) { 28 $child_count = $node->childNodes->length; 29 } else { 30 $child_count = 0; 31 } 32 print "\nNum Children: " . $child_count; 33 if($child_count <= 1){ 34 if (strlen(trim($node->nodeValue))) { 35 print "\nNode Content: " . $node->nodeValue; 36 } else { 37 print "\nNode Content:"; 38 } 39 } 40 print "\n\n"; 41} 42 43function print_node_list($nodelist) 44{ 45 foreach($nodelist as $node) 46 { 47 print_node($node); 48 } 49} 50 51function print_node_compact($node, $spaces) 52{ 53 if ($node->nodeType == 3) { 54 print str_repeat(" ", $spaces) . trim($node->nodeValue) . "\n"; 55 } else { 56 print str_repeat(" ", $spaces) . "<" . $node->nodeName . ">\n"; 57 print_node_list_compact($node->childNodes, $spaces + 2); 58 print str_repeat(" ", $spaces) . "</" . $node->nodeName . ">\n"; 59 } 60} 61 62function print_node_list_compact($nodelist, $spaces = 0) 63{ 64 foreach ($nodelist as $node) { 65 print_node_compact($node, $spaces); 66 } 67} 68 69?> 70