Skip to content

XML depth/previousDepth are not correctly handled #590

@FunkyOz

Description

@FunkyOz

Hi everyone,
I think that XML depth is not correctly handled and xml adapter does not work properly.

If you use a deep xml scructure like this:

<?xml version="1.0" encoding="utf-8"?>
<root>
    <cars>
        <car>
            <model>
                <make>Mercedes</make>
            </model>
        </car>
        <car>
            <model>
                <make>BMW</make>
            </model>
        </car>
        <car>
            <model>
                <make>Nissan</make>
            </model>
        </car>
    </cars>
</root>

And run process

(new Flow())
    ->read(XML::from($filepath, 'root/cars/car'))
    ->write(\Flow\ETL\DSL\To::output(false))
    ->run();

The result is

+----------------------------------------------------------------------------------------------------------------------+
|                                                                                                                 node |
+----------------------------------------------------------------------------------------------------------------------+
| <?xml version="1.0"?><car>            <model>                <make>Mercedes</make>            </model>        </car> |
+----------------------------------------------------------------------------------------------------------------------+

But I expect this output

+----------------------------------------------------------------------------------------------------------------------+
|                                                                                                                 node |
+----------------------------------------------------------------------------------------------------------------------+
| <?xml version="1.0"?><car>            <model>                <make>Mercedes</make>            </model>        </car> |
|      <?xml version="1.0"?><car>            <model>                <make>BMW</make>            </model>        </car> |
|   <?xml version="1.0"?><car>            <model>                <make>Nissan</make>            </model>        </car> |
+----------------------------------------------------------------------------------------------------------------------+

Maybe I'm wrong and I don't understand the intent behind this adapter but I think that internally he does not correctly handle the depth/previous depth.

Look at XMLReaderExtractor::extract at line 60 and supposed to be in depth 4 (meaning <make> tag, the deepest tag found).

In the next iteration previousDepth=4 and and depth=2 (meaning <car>, because reader back up to parent).
So the only entered if statement is $xmlReadler->depth < $previousDepth and \array_pop($currentPathBreadCrumbs) line was executed.

So now $currentPathBreadCrumbs is ['root', 'cars', 'car', 'model'] but is not the correct path (remember that reader back up to <car>).

I expect that in case of $depth < $previousDepth we should be remove all tags with depth between $xmlReadler->depth and $previousDepth and in this specific case $currentPathBreadCrumbs should be ['root', 'cars', 'car'].

Thanks, I hope I was clear :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions