Skip to content

Commit 4babdfc

Browse files
authored
addressed issue #11786
The following issue has been addressed: Repeated entry in the Serializer components doc #11786 The separate documentations for XMLEncoder were put into one section with minor changes in text. The documentation now contains one single section for XMLEncoder.
1 parent 50d70f1 commit 4babdfc

File tree

1 file changed

+43
-70
lines changed

1 file changed

+43
-70
lines changed

components/serializer.rst

Lines changed: 43 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -804,8 +804,20 @@ The ``XmlEncoder`` will encode this object like that::
804804
<bar>1</bar>
805805
</response>
806806

807-
Be aware that this encoder will consider keys beginning with ``@`` as attributes, and will use
808-
the key ``#comment`` for encoding XML comments::
807+
It is noteworthy that the special ``#`` key can be used to define the data of a node::
808+
809+
['foo' => ['@bar' => 'value', '#' => 'baz']];
810+
811+
// is encoded as follows:
812+
// <?xml version="1.0"?>
813+
// <response>
814+
// <foo bar="value">
815+
// baz
816+
// </foo>
817+
// </response>
818+
819+
820+
Furthermore, keys beginning with ``@`` will be considered attributes, and the key ``#comment`` can be used for encoding XML comments::
809821

810822
$encoder = new XmlEncoder();
811823
$encoder->encode([
@@ -831,6 +843,35 @@ always as a collection.
831843
Data with ``#comment`` keys are encoded to XML comments by default. This can be
832844
changed with the optional ``$encoderIgnoredNodeTypes`` argument of the
833845
``XmlEncoder`` class constructor.
846+
847+
The Context parameter of XmlEncoder
848+
~~~~~~~
849+
850+
The ``encode()`` method defines a third optional parameter called ``context``
851+
which defines the configuration options for the XmlEncoder an associative array::
852+
853+
$xmlEncoder->encode($array, 'xml', $context);
854+
855+
These are the options available:
856+
857+
``xml_format_output``
858+
If set to true, formats the generated XML with line breaks and indentation.
859+
860+
``xml_version``
861+
Sets the XML version attribute (default: ``1.1``).
862+
863+
``xml_encoding``
864+
Sets the XML encoding attribute (default: ``utf-8``).
865+
866+
``xml_standalone``
867+
Adds standalone attribute in the generated XML (default: ``true``).
868+
869+
``xml_root_node_name``
870+
Sets the root node name (default: ``response``).
871+
872+
``remove_empty_tags``
873+
If set to true, removes all empty tags in the generated XML.
874+
834875

835876
The ``YamlEncoder``
836877
~~~~~~~~~~~~~~~~~~~
@@ -1143,74 +1184,6 @@ you indicate that you're expecting an array instead of a single object::
11431184
$data = ...; // The serialized data from the previous example
11441185
$persons = $serializer->deserialize($data, 'Acme\Person[]', 'json');
11451186

1146-
The ``XmlEncoder``
1147-
------------------
1148-
1149-
This encoder transforms arrays into XML and vice versa. For example, take an
1150-
object normalized as following::
1151-
1152-
['foo' => [1, 2], 'bar' => true];
1153-
1154-
The ``XmlEncoder`` encodes this object as follows:
1155-
1156-
.. code-block:: xml
1157-
1158-
<?xml version="1.0"?>
1159-
<response>
1160-
<foo>1</foo>
1161-
<foo>2</foo>
1162-
<bar>1</bar>
1163-
</response>
1164-
1165-
The array keys beginning with ``@`` are considered XML attributes::
1166-
1167-
['foo' => ['@bar' => 'value']];
1168-
1169-
// is encoded as follows:
1170-
// <?xml version="1.0"?>
1171-
// <response>
1172-
// <foo bar="value"/>
1173-
// </response>
1174-
1175-
Use the special ``#`` key to define the data of a node::
1176-
1177-
['foo' => ['@bar' => 'value', '#' => 'baz']];
1178-
1179-
// is encoded as follows:
1180-
// <?xml version="1.0"?>
1181-
// <response>
1182-
// <foo bar="value">
1183-
// baz
1184-
// </foo>
1185-
// </response>
1186-
1187-
Context
1188-
~~~~~~~
1189-
1190-
The ``encode()`` method defines a third optional parameter called ``context``
1191-
which defines the configuration options for the XmlEncoder an associative array::
1192-
1193-
$xmlEncoder->encode($array, 'xml', $context);
1194-
1195-
These are the options available:
1196-
1197-
``xml_format_output``
1198-
If set to true, formats the generated XML with line breaks and indentation.
1199-
1200-
``xml_version``
1201-
Sets the XML version attribute (default: ``1.1``).
1202-
1203-
``xml_encoding``
1204-
Sets the XML encoding attribute (default: ``utf-8``).
1205-
1206-
``xml_standalone``
1207-
Adds standalone attribute in the generated XML (default: ``true``).
1208-
1209-
``xml_root_node_name``
1210-
Sets the root node name (default: ``response``).
1211-
1212-
``remove_empty_tags``
1213-
If set to true, removes all empty tags in the generated XML.
12141187

12151188
Handling Constructor Arguments
12161189
------------------------------

0 commit comments

Comments
 (0)