XMLReaderIterator icon indicating copy to clipboard operation
XMLReaderIterator copied to clipboard

Call to getChildElements() makes the iteration skip steps

Open greg0ire opened this issue 9 years ago • 8 comments

I'm trying to read an xml file created with mysqldump --xml

The code looks like this :

<?php

        $reader = new \XMLReader();
        $reader->open($this->filename);
        $objects = new \XMLElementIterator($reader, 'row');

        foreach ($objects as $key => $row) {
            echo 'importing row #' . ($key + 1) . PHP_EOL;

            $this->importRow($row, $manager);
        }

The importRow method loops over fields. It looks like this :

        foreach ($row->getChildElements() as $field) {
            $this->setValue(
                $entity,
                $field->getAttribute('name'),
                (string) $field
            );
        }

When I comment out the importRow() call I get the right number of iterations. When I do not, I get half, and only entities with even ids get imported. It is as if the getChildElements() call would make the pointer increase.

Am I using the library wrong ?

greg0ire avatar Oct 08 '14 16:10 greg0ire