@@ -804,8 +804,20 @@ The ``XmlEncoder`` will encode this object like that::
804
804
<bar>1</bar>
805
805
</response>
806
806
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::
809
821
810
822
$encoder = new XmlEncoder();
811
823
$encoder->encode([
@@ -831,6 +843,35 @@ always as a collection.
831
843
Data with ``#comment `` keys are encoded to XML comments by default. This can be
832
844
changed with the optional ``$encoderIgnoredNodeTypes `` argument of the
833
845
``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
+
834
875
835
876
The ``YamlEncoder ``
836
877
~~~~~~~~~~~~~~~~~~~
@@ -1143,74 +1184,6 @@ you indicate that you're expecting an array instead of a single object::
1143
1184
$data = ...; // The serialized data from the previous example
1144
1185
$persons = $serializer->deserialize($data, 'Acme\Person[]', 'json');
1145
1186
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.
1214
1187
1215
1188
Handling Constructor Arguments
1216
1189
------------------------------
0 commit comments