public function next() { if (parent::valid()) { $this->index++; } parent::next(); $this->ensureCurrentElementState(); }
public function valid() { $parent = parent::valid(); // Prevent skipping elements due to self closing tags. if ($this->reader->depth <= $this->stopDepth && $this->startName != $this->reader->name) { self::$goToNext = false; } return $parent and $this->reader->depth > $this->stopDepth; }
/** * @test */ function iteration() { $reader = new XMLReaderStub('<r><a>1</a><a>2</a></r>'); $it = new XMLReaderIterator($reader); $this->assertSame(null, $it->valid()); $it->rewind(); $this->assertSame(true, $it->valid()); $node = $it->current(); $this->assertEquals('r', $node->getName()); $this->assertEquals('12', (string) $node); $it->moveToNextElementByName('a'); $node = $it->current(); $this->assertEquals('a', $node->getName()); $this->assertEquals('1', (string) $node); $it->moveToNextElementByName('a'); $node = $it->current(); $this->assertEquals('a', $node->getName()); $this->assertEquals('2', (string) $node); $it->next(); $it->next(); $this->assertEquals(XMLReader::END_ELEMENT, $reader->nodeType); $this->assertEquals('a', $it->current()->getName()); $it->next(); $it->next(); $this->assertEquals(false, $it->valid()); }
public function valid() { $parent = parent::valid(); return $parent and $this->reader->depth > $this->stopDepth; }