Skip to content

Unexpected closing tags #16

Description

@hashhesh

Hi @AaronDDM
thanks for this lib it's more connivant.
Could you please help I have came across with really weird closing tag accidently even i didn't understood how/why
So this is my code

    $xmlWriterService = new XMLWriterService();
    $xml_builder_obj = new XMLBuilder($xmlWriterService);
    $root = $xml_builder_obj->createXMLArray()->start('ProductData');

    $root->loop(
        function (XMLArray $XMLArray) use ($results, $relatives_tags, $product_type_attributes) {

            foreach ($product_type_attributes as $tag_index => $tag_value) {
                if (is_array($tag_value) && fn_he_amazon_array_depth($tag_value) === 1) {

                    $groups = $relatives_tags(key($tag_value));

                    $XMLArray->add(key($tag_value), $results[$groups[1]], [explode(',',$groups[2])[2] => $results[$groups[2]]]);

                } else {
                    $XMLArray->add($tag_index, $tag_value);
                }
            }
        });
    $root->end();

and this is the outcomes

<?xml version="1.0" encoding="UTF-8"?>
<ProductData>
    <Viscosity>2T</Viscosity>
    <BatteryAverageLife unitOfMeasure="days">2</BatteryAverageLife>
</ProductData>
<ColorMap>beige</ColorMap>
<SizeMap>XX-Small</SizeMap>
<CompatibleWithVehicleType>Airplane</CompatibleWithVehicleType>

while the expected output is like below:

<?xml version="1.0" encoding="UTF-8"?>
<ProductData>
        <Viscosity>2T</Viscosity>
        <BatteryAverageLife unitOfMeasure="days">2</BatteryAverageLife>
        <ColorMap>beige</ColorMap>
        <SizeMap>XX-Small</SizeMap>
       <CompatibleWithVehicleType>Airplane</CompatibleWithVehicleType>
</ProductData>

ProductData should be closed at the end not to be closed after the second tag.
I have used startLoop and using $root instead of XMLArray but the same result.

So, Could you please help to understand this issue? though if I comment the first if statement it's works fine.

Thanks in advance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions