1--TEST-- 2SPL: SimpleXMLIterator and overridden iterator methods() 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 38class SXETest extends SimpleXMLIterator 39{ 40 function rewind() 41 { 42 echo __METHOD__ . "\n"; 43 return parent::rewind(); 44 } 45 function valid() 46 { 47 echo __METHOD__ . "\n"; 48 return parent::valid(); 49 } 50 function current() 51 { 52 echo __METHOD__ . "\n"; 53 return parent::current(); 54 } 55 function key() 56 { 57 echo __METHOD__ . "\n"; 58 return parent::key(); 59 } 60 function next() 61 { 62 echo __METHOD__ . "\n"; 63 return parent::next(); 64 } 65 function hasChildren() 66 { 67 echo __METHOD__ . "\n"; 68 return parent::hasChildren(); 69 } 70 function getChildren() 71 { 72 echo __METHOD__ . "\n"; 73 return parent::getChildren(); 74 } 75} 76 77$sxe = new SXETest($xml); 78$rit = new RecursiveIteratorIterator($sxe, RecursiveIteratorIterator::SELF_FIRST); 79 80foreach($rit as $data) { 81 var_dump(get_class($data)); 82 var_dump(trim($data)); 83} 84 85?> 86===DONE=== 87--EXPECTF-- 88SXETest::rewind 89SXETest::valid 90SXETest::hasChildren 91SXETest::valid 92SXETest::current 93string(7) "SXETest" 94string(10) "Bla bla 1." 95SXETest::getChildren 96SXETest::rewind 97SXETest::valid 98SXETest::hasChildren 99SXETest::valid 100SXETest::current 101string(7) "SXETest" 102string(28) "Here we have some text data." 103SXETest::getChildren 104SXETest::rewind 105SXETest::valid 106SXETest::hasChildren 107SXETest::valid 108SXETest::current 109string(7) "SXETest" 110string(19) "And here some more." 111SXETest::getChildren 112SXETest::rewind 113SXETest::valid 114SXETest::hasChildren 115SXETest::valid 116SXETest::current 117string(7) "SXETest" 118string(15) "Wow once again." 119SXETest::next 120SXETest::valid 121SXETest::next 122SXETest::valid 123SXETest::next 124SXETest::valid 125SXETest::next 126SXETest::valid 127SXETest::hasChildren 128SXETest::valid 129SXETest::current 130string(7) "SXETest" 131string(10) "Bla bla 2." 132SXETest::getChildren 133SXETest::rewind 134SXETest::valid 135SXETest::hasChildren 136SXETest::valid 137SXETest::current 138string(7) "SXETest" 139string(7) "Foo Bar" 140SXETest::next 141SXETest::valid 142SXETest::next 143SXETest::valid 144SXETest::valid 145===DONE=== 146