Skip to content

Commit 84fd8c6

Browse files
committed
minor #16845 [Serializer] Update serializer.rst (issamkhadiri1989)
This PR was merged into the 6.0 branch. Discussion ---------- [Serializer] Update serializer.rst Hello The `$encoderIgnoredNodeTypes` does not exist in the XmlEncoder's constructor and the $defaultContext argument should be used instead, So To escape the comments while encoding, we can either pass the `\XML_COMMENT_NODE` to the `XmlEncoder::ENCODER_IGNORED_NODE_TYPES` context option in the constructor or use it when calling the encode() method. <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/releases for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `6.x` for features of unreleased versions). --> Commits ------- f126ce1 Update serializer.rst
2 parents f3a612d + f126ce1 commit 84fd8c6

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

components/serializer.rst

+4-2
Original file line numberDiff line numberDiff line change
@@ -1080,8 +1080,10 @@ always as a collection.
10801080
behavior can be changed with the optional context key ``XmlEncoder::DECODER_IGNORED_NODE_TYPES``.
10811081

10821082
Data with ``#comment`` keys are encoded to XML comments by default. This can be
1083-
changed with the optional ``$encoderIgnoredNodeTypes`` argument of the
1084-
``XmlEncoder`` class constructor.
1083+
changed by adding the ``\XML_COMMENT_NODE`` option to the ``XmlEncoder::ENCODER_IGNORED_NODE_TYPES`` key of the ``$defaultContext`` of the
1084+
``XmlEncoder`` class constructor or directly to the encode() method's $context argument.
1085+
1086+
$xmlEncoder->encode($array, 'xml', [XmlEncoder::ENCODER_IGNORED_NODE_TYPES => [\XML_COMMENT_NODE]]);
10851087

10861088
The ``XmlEncoder`` Context Options
10871089
..................................

0 commit comments

Comments
 (0)