-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer][XmlEncoder] Allow removing empty tags in generated XML #20524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -393,7 +393,9 @@ private function buildXml(\DOMNode $parentNode, $data, $xmlRootNodeName = null) | |||
} elseif (is_numeric($key) || !$this->isElementNameValid($key)) { | |||
$append = $this->appendNode($parentNode, $data, 'item', $key); | |||
} else { | |||
$append = $this->appendNode($parentNode, $data, $key); | |||
if ($data !== null || !isset($this->context['remove_empty_tags']) || $this->context['remove_empty_tags'] === false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be elseif
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and please also use a Yoda condition here: null !== $data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's done :
} elseif (null !== $data || !isset($this->context['remove_empty_tags']) || false === $this->context['remove_empty_tags']) {
$append = $this->appendNode($parentNode, $data, $key);
}
Use Yoda conditions
$expected = '<?xml version="1.0"?>'."\n". | ||
'<response><person><firstname>Peter</firstname></person></response>'."\n"; | ||
|
||
$context = array( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be inline
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right i have made the modification
👍 |
Can you open a doc PR please @amoiraud |
Thank you @amoiraud. |
…generated XML (amoiraud) This PR was squashed before being merged into the 3.3-dev branch (closes #20524). Discussion ---------- [Serializer][XmlEncoder] Allow removing empty tags in generated XML | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #20398 | License | MIT | Doc PR | ~ Allow a new option in $context of XmlEncoder.php to remove empty tags if $context['remove_empty_tags'] setted to true, changing this : ```xml <node> <subnode>Value</subnode> <emptysubnode/> </node> ``` To this : ```xml <node> <subnode>Value</subnode> </node> ``` Commits ------- 0cb4d8e [Serializer][XmlEncoder] Allow removing empty tags in generated XML
Hi @dunglas |
@amoiraud, I suggest to add a new section about the |
… javiereguiluz) This PR was submitted for the master branch but it was merged into the 3.3 branch instead (closes #7231). Discussion ---------- Add documentation for XmlEncoder context param Add documentation for XmlEncoder context param Related to : symfony/symfony#20524 This fixes #7227 Commits ------- 5e23045 Minor tweaks adbc7b2 Minor rewords 2dc6ed3 Minor syntax issue 6050370 Minor syntax issues and some rewordings 2f3cf02 Correcting my bad english with a bilingual friend 60c7657 Add XmlEncoder documentation with $context available options 04af434 erratum c83e59d Add XmlEncoder documentation with $context available options
Allow a new option in $context of XmlEncoder.php to remove empty tags if $context['remove_empty_tags'] setted to true, changing this :
To this :