1--TEST-- 2SPL: SimpleXMLIterator and getChildren() 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($sxe->getChildren() as $name => $data) { 39 var_dump($name); 40 var_dump(get_class($data)); 41 var_dump(trim($data)); 42} 43 44echo "===RESET===\n"; 45 46for ($sxe->rewind(); $sxe->valid(); $sxe->next()) { 47 var_dump($sxe->hasChildren()); 48 var_dump(trim($sxe->key())); 49 var_dump(trim($sxe->current())); 50 foreach($sxe->getChildren() as $name => $data) { 51 var_dump($name); 52 var_dump(get_class($data)); 53 var_dump(trim($data)); 54 } 55} 56 57?> 58--EXPECTF-- 59Warning: foreach() argument must be of type array|object, null given in %ssxe_003.php on line %d 60===RESET=== 61bool(true) 62string(5) "elem1" 63string(10) "Bla bla 1." 64string(5) "elem2" 65string(17) "SimpleXMLIterator" 66string(28) "Here we have some text data." 67bool(true) 68string(6) "elem11" 69string(10) "Bla bla 2." 70string(7) "elem111" 71string(17) "SimpleXMLIterator" 72string(7) "Foo Bar" 73