Skip to content

Call to getChildElements() makes the iteration skip steps  #3

Description

@greg0ire

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 ?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions