xref: /PHP-5.4/ext/simplexml/tests/sxe_003.phpt (revision 610c7fbe)
1--TEST--
2SPL: SimpleXMLIterator and getChildren()
3--SKIPIF--
4<?php
5if (!extension_loaded('simplexml')) print 'skip';
6if (!extension_loaded("libxml")) print "skip LibXML not present";
7?>
8--FILE--
9<?php
10
11$xml =<<<EOF
12<?xml version='1.0'?>
13<!DOCTYPE sxe SYSTEM "notfound.dtd">
14<sxe id="elem1">
15 Plain text.
16 <elem1 attr1='first'>
17  Bla bla 1.
18  <!-- comment -->
19  <elem2>
20   Here we have some text data.
21   <elem3>
22    And here some more.
23    <elem4>
24     Wow once again.
25    </elem4>
26   </elem3>
27  </elem2>
28 </elem1>
29 <elem11 attr2='second'>
30  Bla bla 2.
31  <elem111>
32   Foo Bar
33  </elem111>
34 </elem11>
35</sxe>
36EOF;
37
38$sxe = simplexml_load_string((binary)$xml, 'SimpleXMLIterator');
39
40foreach($sxe->getChildren() as $name => $data) {
41	var_dump($name);
42	var_dump(get_class($data));
43	var_dump(trim($data));
44}
45
46echo "===RESET===\n";
47
48for ($sxe->rewind(); $sxe->valid(); $sxe->next()) {
49	var_dump($sxe->hasChildren());
50	var_dump(trim($sxe->key()));
51	var_dump(trim($sxe->current()));
52	foreach($sxe->getChildren() as $name => $data) {
53		var_dump($name);
54		var_dump(get_class($data));
55		var_dump(trim($data));
56	}
57}
58
59?>
60===DONE===
61--EXPECTF--
62
63Warning: Invalid argument supplied for foreach() in %ssxe_003.php on line %d
64===RESET===
65bool(true)
66string(5) "elem1"
67string(10) "Bla bla 1."
68string(5) "elem2"
69string(17) "SimpleXMLIterator"
70string(28) "Here we have some text data."
71bool(true)
72string(6) "elem11"
73string(10) "Bla bla 2."
74string(7) "elem111"
75string(17) "SimpleXMLIterator"
76string(7) "Foo Bar"
77===DONE===
78