AaronDDM/XMLBuilder

How to loop without parent node ?

t-prod opened this issue · 4 comments

Hi,

Thanks for your package. I would like to loop by adding in XML

<Line>
<Sku>XXX</Sku>
<Qty>1</Qty>
</Line>

With this it creates a parent node but I don't need to. How can I do to only do a simple loop without a parent node ?

->startLoop('Users', [], function (XMLArray $XMLArray) use ($users) {
                foreach ($users as $user) {
                    $XMLArray->start('User')
                        ->add('name', $user['name'])
                        ->add('age', $user['age']);
                }
            })
            ->end()

You should be able to just use "loop" instead of "startLoop" if I understood you right, thats what I currently do:

->loop(function (XMLArray $XMLArray) use ($users) {
    foreach ($users as $user) {
        $XMLArray->start('User')
            ->add('name', $user['name'])
            ->add('age', $user['age']);
    }
})

That's perfect I did not see the loop function ;) Thanks again

@AaronDDM, please add loop method to README.md

Will do, thanks guys!