Skip to content

Commit f126ce1

Browse files
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.
1 parent 8c48d04 commit f126ce1

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
@@ -1108,8 +1108,10 @@ always as a collection.
11081108
behavior can be changed with the optional context key ``XmlEncoder::DECODER_IGNORED_NODE_TYPES``.
11091109

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

11141116
The ``XmlEncoder`` Context Options
11151117
..................................

0 commit comments

Comments
 (0)