File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -798,14 +798,16 @@ The ``XmlEncoder`` will encode this object like that::
798
798
<bar>1</bar>
799
799
</response>
800
800
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::
802
803
803
804
$encoder = new XmlEncoder();
804
- $encoder->encode(array('foo' => array('@bar' => 'value')));
805
+ $encoder->encode(array('foo' => array('@bar' => 'value'), 'qux' => array('#comment' => 'A comment ));
805
806
// will return:
806
807
// <?xml version="1.0"?>
807
808
// <response>
808
809
// <foo bar="value" />
810
+ // <qux><!-- A comment --!><qux>
809
811
// </response>
810
812
811
813
You can pass the context key ``as_collection `` in order to have the results
@@ -817,9 +819,13 @@ always as a collection.
817
819
.. tip ::
818
820
819
821
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
821
823
the ``XmlEncoder `` class constructor.
822
824
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
+
823
829
.. versionadded :: 4.1
824
830
XML comments are ignored by default starting from Symfony 4.1.
825
831
You can’t perform that action at this time.
0 commit comments