xref: /PHP-8.3/ext/dom/tests/dom007.phpt (revision bd9f4fa6)
1--TEST--
2Test 7: DTD tests
3--EXTENSIONS--
4dom
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>
34EOXML;
35
36$dom = new DOMDocument();
37$dom->loadXML($xml);
38
39$dtd = $dom->doctype;
40
41/* Notation Tests */
42$nots = $dtd->notations;
43
44$length = $nots->length;
45echo "Length: ".$length."\n";
46
47foreach ($nots AS $key=>$node) {
48    echo "Key $key: ".$node->nodeName." (".$node->systemId.") (".$node->publicId.")\n";
49}
50print "\n";
51for($x=0; $x < $length; $x++) {
52    echo "Index $x: ".$nots->item($x)->nodeName." (".$nots->item($x)->systemId.") (".$nots->item($x)->publicId.")\n";
53}
54
55echo "\n";
56$node = $nots->getNamedItem('xxx');
57var_dump($node);
58
59echo "\n";
60/* Entity Decl Tests */
61$ents = $dtd->entities;
62$length = $ents->length;
63echo "Length: ".$length."\n";
64
65$xkeys = array();
66foreach ($ents AS $key=>$node) {
67    $xkeys[] = "Key: $key Name: ".$node->nodeName."\n";
68}
69sort($xkeys);  // fix inconsistent output ordering (bug #61810)
70foreach ($xkeys as $key => $node) {
71    echo $node;
72}
73echo "\n";
74
75$xkeys = array();
76for($x=0; $x < $length; $x++) {
77    $xkeys[] = "Index: ".$ents->item($x)->nodeName."\n";
78}
79sort($xkeys);  // fix inconsistent output ordering (bug #61810)
80foreach ($xkeys as $key => $node) {
81    echo $node;
82}
83
84echo "\n";
85$node = $ents->item(3);
86var_dump($node);
87$node = $ents->getNamedItem('xxx');
88var_dump($node);
89?>
90--EXPECT--
91Length: 1
92Key GIF: GIF (image/gif) (-)
93
94Index 0: GIF (image/gif) (-)
95
96NULL
97
98Length: 3
99Key: myimage Name: myimage
100Key: rdf Name: rdf
101Key: test Name: test
102
103Index: myimage
104Index: rdf
105Index: test
106
107NULL
108NULL
109