summaryrefslogtreecommitdiff
path: root/ext/dom/tests/dom001.phpt
blob: a0c78fbb0a19f839d92cedf22f92af8a4c049e60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
--TEST--
Test 1: Accessing single node
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
require_once("dom_test.inc");

echo "Test 1: accessing single nodes from php\n";
$dom = new domDocument;
$dom->loadxml($xmlstr);
if(!$dom) {
  echo "Error while parsing the document\n";
  exit;
}

// children() of of document would result in a memleak
//$children = $dom->children();
//print_node_list($children);

echo "--------- root\n";
$rootnode = $dom->documentElement;
print_node($rootnode);

echo "--------- children of root\n";
$children = $rootnode->childNodes;
print_node_list($children);

// The last node should be identical with the last entry in the children array
echo "--------- last\n";
$last = $rootnode->lastChild;
print_node($last);

// The parent of this last node is the root again
echo "--------- parent\n";
$parent = $last->parentNode;
print_node($parent);

// The children of this parent are the same children as one above
echo "--------- children of parent\n";
$children = $parent->childNodes;
print_node_list($children);

echo "--------- creating a new attribute\n";
//This is worthless
//$attr = $dom->createAttribute("src", "picture.gif");
//print_r($attr);

//$rootnode->set_attributeNode($attr); 
$attr = $rootnode->setAttribute("src", "picture.gif");
$attr = $rootnode->getAttribute("src");
print_r($attr);
print "\n";

echo "--------- Get Attribute Node\n";
$attr = $rootnode->getAttributeNode("src");
print_node($attr);

echo "--------- Remove Attribute Node\n";
$attr = $rootnode->removeAttribute("src");
print "Removed " . $attr . " attributes.\n";

echo "--------- attributes of rootnode\n";
$attrs = $rootnode->attributes;
print_node_list($attrs);

echo "--------- children of an attribute\n";
$children = $attrs->item(0)->childNodes;
print_node_list($children);

echo "--------- Add child to root\n";
$myelement = new domElement("Silly", "Symphony");
$newchild = $rootnode->appendChild($myelement);
print_node($newchild);
print $dom->saveXML();
print "\n";

echo "--------- Find element by tagname\n";
echo "    Using dom\n";
$children = $dom->getElementsByTagname("Silly");
print_node_list($children);

echo "    Using elem\n";
$children = $rootnode->getElementsByTagName("Silly");
print_node_list($children);

echo "--------- Unlink Node\n";
print_node($children->item(0));
$rootnode->removeChild($children->item(0));
print_node_list($rootnode->childNodes);
print $dom->savexml();

echo "--------- Find element by id\n";
print ("Not implemented\n");

echo "--------- Check various node_name return values\n";
print ("Not needed\n");

?>
--EXPECT--
Test 1: accessing single nodes from php
--------- root
Node Name: chapter
Node Type: 1
Num Children: 4

--------- children of root
Node Name: title
Node Type: 1
Num Children: 1
Node Content: Title

Node Name: #text
Node Type: 3
Num Children: 0
Node Content: 


Node Name: para
Node Type: 1
Num Children: 7

Node Name: #text
Node Type: 3
Num Children: 0
Node Content: 


--------- last
Node Name: #text
Node Type: 3
Num Children: 0
Node Content: 


--------- parent
Node Name: chapter
Node Type: 1
Num Children: 4

--------- children of parent
Node Name: title
Node Type: 1
Num Children: 1
Node Content: Title

Node Name: #text
Node Type: 3
Num Children: 0
Node Content: 


Node Name: para
Node Type: 1
Num Children: 7

Node Name: #text
Node Type: 3
Num Children: 0
Node Content: 


--------- creating a new attribute
picture.gif
--------- Get Attribute Node
Node Name: src
Node Type: 2
Num Children: 1
Node Content: picture.gif

--------- Remove Attribute Node
Removed 1 attributes.
--------- attributes of rootnode
Node Name: language
Node Type: 2
Num Children: 1
Node Content: en

--------- children of an attribute
Node Name: #text
Node Type: 3
Num Children: 0
Node Content: en

--------- Add child to root
Node Name: Silly
Node Type: 1
Num Children: 1
Node Content: Symphony

<?xml version="1.0" standalone="yes"?>
<!DOCTYPE chapter SYSTEM "/share/sgml/Norman_Walsh/db3xml10/db3xml10.dtd" [
<!ENTITY sp "spanish">
]>
<!-- lsfj  -->
<chapter language="en"><title language="en">Title</title>
<para language="ge">
&sp;
<!-- comment -->
<informaltable language="&sp;kkk">
<tgroup cols="3">
<tbody>
<row><entry>a1</entry><entry morerows="1">b1</entry><entry>c1</entry></row>
<row><entry>a2</entry><entry>c2</entry></row>
<row><entry>a3</entry><entry>b3</entry><entry>c3</entry></row>
</tbody>
</tgroup>
</informaltable>
</para>
<Silly>Symphony</Silly></chapter>

--------- Find element by tagname
    Using dom
Node Name: Silly
Node Type: 1
Num Children: 1
Node Content: Symphony

    Using elem
Node Name: Silly
Node Type: 1
Num Children: 1
Node Content: Symphony

--------- Unlink Node
Node Name: Silly
Node Type: 1
Num Children: 1
Node Content: Symphony

Node Name: title
Node Type: 1
Num Children: 1
Node Content: Title

Node Name: #text
Node Type: 3
Num Children: 0
Node Content: 


Node Name: para
Node Type: 1
Num Children: 7

Node Name: #text
Node Type: 3
Num Children: 0
Node Content: 


<?xml version="1.0" standalone="yes"?>
<!DOCTYPE chapter SYSTEM "/share/sgml/Norman_Walsh/db3xml10/db3xml10.dtd" [
<!ENTITY sp "spanish">
]>
<!-- lsfj  -->
<chapter language="en"><title language="en">Title</title>
<para language="ge">
&sp;
<!-- comment -->
<informaltable language="&sp;kkk">
<tgroup cols="3">
<tbody>
<row><entry>a1</entry><entry morerows="1">b1</entry><entry>c1</entry></row>
<row><entry>a2</entry><entry>c2</entry></row>
<row><entry>a3</entry><entry>b3</entry><entry>c3</entry></row>
</tbody>
</tgroup>
</informaltable>
</para>
</chapter>
--------- Find element by id
Not implemented
--------- Check various node_name return values
Not needed