Skip to content

[Serializer] XmlEncoder : Add a way to remove empty tags #20398

@amoiraud

Description

@amoiraud

Hi I have to generate an XML without any empty tags.

Right now I use the XmlEncoder to generate it and I have some thing like :

    <node>
         <subnode>Value</subnode>
          <emptysubnode/>
    </node>

And what I need in output is :

    <node>
         <subnode>Value</subnode>
    </node>

I can acheive this by changing XmlEncoder buildXml method L396 :

changing this :

    } elseif (is_numeric($key) || !$this->isElementNameValid($key)) {
        $append = $this->appendNode($parentNode, $data, 'item', $key);
    } else {
        $append = $this->appendNode($parentNode, $data, $key);
    }

to this

    } elseif (is_numeric($key) || !$this->isElementNameValid($key)) {
        $append = $this->appendNode($parentNode, $data, 'item', $key);
    } else {
        if ($data !== null) {
            $append = $this->appendNode($parentNode, $data, $key);
        }
    }

Is there a way to do that ? or we can add this feature but I don't really see how to do it ?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions