You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.8 KiB

  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. echo "Test 1: accessing single nodes from php\n";
  23. $dom = xmldoc($xmlstr);
  24. if(!$dom) {
  25. echo "Error while parsing the document\n";
  26. exit;
  27. }
  28. $children = $dom->childNodes();
  29. print_r($children);
  30. echo "--------- root\n";
  31. $rootnode = $dom->documentElement();
  32. print_r($rootnode);
  33. echo "--------- children of root\n";
  34. $children = $rootnode->childNodes();
  35. print_r($children);
  36. // The last node should be identical with the last entry in the children array
  37. echo "--------- last\n";
  38. $last = $rootnode->lastChild();
  39. print_r($last);
  40. // The parent of this last node is the root again
  41. echo "--------- parent\n";
  42. $parent = $last->parent();
  43. print_r($parent);
  44. // The children of this parent are the same children as one above
  45. echo "--------- children of parent\n";
  46. $children = $parent->childNodes();
  47. print_r($children);
  48. echo "--------- creating a new attribute\n";
  49. $attr = $dom->createAttribute("src", "picture.gif");
  50. print_r($attr);
  51. $rootnode->setAttributeNode($attr); /* Not implemented */
  52. $attr = $rootnode->setAttribute("src", "picture.gif");
  53. $attr = $rootnode->getAttribute("src");
  54. print_r($attr);
  55. echo "--------- attribute of rootnode\n";
  56. $attrs = $rootnode->attributes();
  57. print_r($attrs);
  58. echo "--------- children of an attribute\n";
  59. $children = $attrs[0]->childNodes();
  60. print_r($children);
  61. ?>