xref: /PHP-8.3/ext/simplexml/tests/sxe_002.phpt (revision 7f2f0c00)
1--TEST--
2SPL: SimpleXMLIterator and recursion
3--EXTENSIONS--
4simplexml
5libxml
6--FILE--
7<?php
8
9$xml =<<<EOF
10<?xml version='1.0'?>
11<!DOCTYPE sxe SYSTEM "notfound.dtd">
12<sxe id="elem1">
13 Plain text.
14 <elem1 attr1='first'>
15  Bla bla 1.
16  <!-- comment -->
17  <elem2>
18   Here we have some text data.
19   <elem3>
20    And here some more.
21    <elem4>
22     Wow once again.
23    </elem4>
24   </elem3>
25  </elem2>
26 </elem1>
27 <elem11 attr2='second'>
28  Bla bla 2.
29  <elem111>
30   Foo Bar
31  </elem111>
32 </elem11>
33</sxe>
34EOF;
35
36$sxe = simplexml_load_string($xml, 'SimpleXMLIterator');
37
38foreach(new RecursiveIteratorIterator($sxe, 1) as $name => $data) {
39    var_dump($name);
40    var_dump(get_class($data));
41    var_dump(trim($data));
42}
43
44echo "===DUMP===\n";
45
46var_dump(get_class($sxe));
47var_dump(trim($sxe->elem1));
48
49?>
50--EXPECT--
51string(5) "elem1"
52string(17) "SimpleXMLIterator"
53string(10) "Bla bla 1."
54string(5) "elem2"
55string(17) "SimpleXMLIterator"
56string(28) "Here we have some text data."
57string(5) "elem3"
58string(17) "SimpleXMLIterator"
59string(19) "And here some more."
60string(5) "elem4"
61string(17) "SimpleXMLIterator"
62string(15) "Wow once again."
63string(6) "elem11"
64string(17) "SimpleXMLIterator"
65string(10) "Bla bla 2."
66string(7) "elem111"
67string(17) "SimpleXMLIterator"
68string(7) "Foo Bar"
69===DUMP===
70string(17) "SimpleXMLIterator"
71string(10) "Bla bla 1."
72