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