dom007.phpt 2.3 KB

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