dom007.phpt 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. --TEST--
  2. Test 7: DTD tests
  3. --EXTENSIONS--
  4. dom
  5. --FILE--
  6. <?php
  7. $xml = <<< EOXML
  8. <?xml version="1.0" encoding="ISO-8859-1"?>
  9. <!DOCTYPE courses [
  10. <!ELEMENT courses (course+)>
  11. <!ELEMENT course (title, description, temp*)>
  12. <!ATTLIST course cid ID #REQUIRED>
  13. <!ELEMENT title (#PCDATA)>
  14. <!ELEMENT description (#PCDATA)>
  15. <!ELEMENT temp (#PCDATA)>
  16. <!ATTLIST temp vid ID #REQUIRED>
  17. <!ENTITY test 'http://www.hpl.hp.com/semweb/2003/query_tester#'>
  18. <!ENTITY rdf 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
  19. <!NOTATION GIF PUBLIC "-" "image/gif">
  20. <!ENTITY myimage PUBLIC "-" "mypicture.gif" NDATA GIF>
  21. ]>
  22. <courses>
  23. <course cid="c1">
  24. <title>Basic Languages</title>
  25. <description>Introduction to Languages</description>
  26. </course>
  27. <course cid="c6">
  28. <title>French I</title>
  29. <description>Introduction to French</description>
  30. <temp vid="c7">
  31. </temp>
  32. </course>
  33. </courses>
  34. EOXML;
  35. $dom = new DOMDocument();
  36. $dom->loadXML($xml);
  37. $dtd = $dom->doctype;
  38. /* Notation Tests */
  39. $nots = $dtd->notations;
  40. $length = $nots->length;
  41. echo "Length: ".$length."\n";
  42. foreach ($nots AS $key=>$node) {
  43. echo "Key $key: ".$node->nodeName." (".$node->systemId.") (".$node->publicId.")\n";
  44. }
  45. print "\n";
  46. for($x=0; $x < $length; $x++) {
  47. echo "Index $x: ".$nots->item($x)->nodeName." (".$nots->item($x)->systemId.") (".$nots->item($x)->publicId.")\n";
  48. }
  49. echo "\n";
  50. $node = $nots->getNamedItem('xxx');
  51. var_dump($node);
  52. echo "\n";
  53. /* Entity Decl Tests */
  54. $ents = $dtd->entities;
  55. $length = $ents->length;
  56. echo "Length: ".$length."\n";
  57. $xkeys = array();
  58. foreach ($ents AS $key=>$node) {
  59. $xkeys[] = "Key: $key Name: ".$node->nodeName."\n";
  60. }
  61. sort($xkeys); // fix inconsistent output ordering (bug #61810)
  62. foreach ($xkeys as $key => $node) {
  63. echo $node;
  64. }
  65. echo "\n";
  66. $xkeys = array();
  67. for($x=0; $x < $length; $x++) {
  68. $xkeys[] = "Index: ".$ents->item($x)->nodeName."\n";
  69. }
  70. sort($xkeys); // fix inconsistent output ordering (bug #61810)
  71. foreach ($xkeys as $key => $node) {
  72. echo $node;
  73. }
  74. echo "\n";
  75. $node = $ents->item(3);
  76. var_dump($node);
  77. $node = $ents->getNamedItem('xxx');
  78. var_dump($node);
  79. ?>
  80. --EXPECT--
  81. Length: 1
  82. Key GIF: GIF (image/gif) (-)
  83. Index 0: GIF (image/gif) (-)
  84. NULL
  85. Length: 3
  86. Key: myimage Name: myimage
  87. Key: rdf Name: rdf
  88. Key: test Name: test
  89. Index: myimage
  90. Index: rdf
  91. Index: test
  92. NULL
  93. NULL