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