dom_test.inc 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. function print_node($node)
  23. {
  24. print "Node Name: " . $node->nodeName;
  25. print "\nNode Type: " . $node->nodeType;
  26. if ($node->nodeType != 3) {
  27. $child_count = $node->childNodes->length;
  28. } else {
  29. $child_count = 0;
  30. }
  31. print "\nNum Children: " . $child_count;
  32. if($child_count <= 1){
  33. if (strlen(trim($node->nodeValue))) {
  34. print "\nNode Content: " . $node->nodeValue;
  35. } else {
  36. print "\nNode Content:";
  37. }
  38. }
  39. print "\n\n";
  40. }
  41. function print_node_list($nodelist)
  42. {
  43. foreach($nodelist as $node)
  44. {
  45. print_node($node);
  46. }
  47. }
  48. function print_node_compact($node, $spaces)
  49. {
  50. if ($node->nodeType == 3) {
  51. print str_repeat(" ", $spaces) . trim($node->nodeValue) . "\n";
  52. } else {
  53. print str_repeat(" ", $spaces) . "<" . $node->nodeName . ">\n";
  54. print_node_list_compact($node->childNodes, $spaces + 2);
  55. print str_repeat(" ", $spaces) . "</" . $node->nodeName . ">\n";
  56. }
  57. }
  58. function print_node_list_compact($nodelist, $spaces = 0)
  59. {
  60. foreach ($nodelist as $node) {
  61. print_node_compact($node, $spaces);
  62. }
  63. }
  64. ?>