Skip to content

Commit 9e3910a

Browse files
hiddewiexabbuh
authored andcommitted
Add XML encoder comment tip and docs
1 parent 2b85af5 commit 9e3910a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

components/serializer.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -798,14 +798,16 @@ The ``XmlEncoder`` will encode this object like that::
798798
<bar>1</bar>
799799
</response>
800800

801-
Be aware that this encoder will consider keys beginning with ``@`` as attributes::
801+
Be aware that this encoder will consider keys beginning with ``@`` as attributes, and will use
802+
the key ``#comment`` for encoding XML comments::
802803

803804
$encoder = new XmlEncoder();
804-
$encoder->encode(array('foo' => array('@bar' => 'value')));
805+
$encoder->encode(array('foo' => array('@bar' => 'value'), 'qux' => array('#comment' => 'A comment));
805806
// will return:
806807
// <?xml version="1.0"?>
807808
// <response>
808809
// <foo bar="value" />
810+
// <qux><!-- A comment --!><qux>
809811
// </response>
810812

811813
You can pass the context key ``as_collection`` in order to have the results
@@ -817,9 +819,13 @@ always as a collection.
817819
.. tip::
818820

819821
XML comments are ignored by default when decoding contents, but this
820-
behavior can be changed with the optional ``$ignoredNodeTypes`` argument of
822+
behavior can be changed with the optional ``$decoderIgnoredNodeTypes`` argument of
821823
the ``XmlEncoder`` class constructor.
822824

825+
Data with ``#comment`` keys are encoded to XML comments by default. This can be
826+
changed with the optional ``$encoderIgnoredNodeTypes`` argument of the
827+
``XmlEncoder`` class constructor.
828+
823829
.. versionadded:: 4.1
824830
XML comments are ignored by default starting from Symfony 4.1.
825831

0 commit comments

Comments
 (0)