Annotation of embedaddon/php/ext/dom/tests/DOMNode_removeChild_basic.phpt, revision 1.1.1.2
1.1 misho 1: --TEST--
2: DOM removeChild : Basic Functionality
3: --SKIPIF--
4: <?php
5: require_once('skipif.inc');
6: ?>
7: --CREDITS--
8: Simon Hughes <odbc3@hotmail.com>
9: --FILE--
10: <?php
11:
12: $xml = <<< EOXML
13: <?xml version="1.0" encoding="ISO-8859-1"?>
14: <courses>
15: <course title="one">
16: <notes>
17: <note>c1n1</note>
18: <note>c1n2</note>
19: </notes>
20: </course>
21: <course title="two">
22: <notes>
23: <note>c2n1</note>
24: <note>c2n2</note>
25: </notes>
26: </course>
27: </courses>
28: EOXML;
29:
30: function dumpcourse($current) {
31: $title = ($current->nodeType != XML_TEXT_NODE && $current->hasAttribute('title')) ? $current->getAttribute('title'):"no title";
1.1.1.2 ! misho 32: echo "Course: $title:";echo get_class($current), "\n";
1.1 misho 33: echo "~";var_dump($current->textContent);
34: }
35:
36: $dom = new DOMDocument();
37: $dom->loadXML($xml);
38: $root = $dom->documentElement;
39:
40: $children = $root->childNodes;
41: $len = $children->length;
42: echo "orignal has $len nodes\n";
43: for ($index = $children->length - 1; $index >=0; $index--) {
44: echo "node $index\n";
45: $current = $children->item($index);
46: dumpcourse($current);
47: if ($current->nodeType == XML_TEXT_NODE) {
48: $noderemoved = $root->removeChild($current);
49: }
50: }
51: $children = $root->childNodes;
52: $len = $children->length;
53: echo "after text removed it now has $len nodes\n";
54: for ($index = 0; $index < $children->length; $index++) {
55: echo "node $index\n";
56: $current = $children->item($index);
57: dumpcourse($current);
58: }
59:
60: --EXPECTF--
61: orignal has 5 nodes
62: node 4
1.1.1.2 ! misho 63: Course: no title:DOMText
1.1 misho 64: ~string(1) "
65: "
66: node 3
1.1.1.2 ! misho 67: Course: two:DOMElement
1.1 misho 68: ~string(24) "
69:
70: c2n1
71: c2n2
72:
73: "
74: node 2
1.1.1.2 ! misho 75: Course: no title:DOMText
1.1 misho 76: ~string(2) "
77: "
78: node 1
1.1.1.2 ! misho 79: Course: one:DOMElement
1.1 misho 80: ~string(24) "
81:
82: c1n1
83: c1n2
84:
85: "
86: node 0
1.1.1.2 ! misho 87: Course: no title:DOMText
1.1 misho 88: ~string(2) "
89: "
90: after text removed it now has 2 nodes
91: node 0
1.1.1.2 ! misho 92: Course: one:DOMElement
1.1 misho 93: ~string(24) "
94:
95: c1n1
96: c1n2
97:
98: "
99: node 1
1.1.1.2 ! misho 100: Course: two:DOMElement
1.1 misho 101: ~string(24) "
102:
103: c2n1
104: c2n2
105:
1.1.1.2 ! misho 106: "
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>