@@ -841,8 +841,20 @@ The ``XmlEncoder`` will encode this object like that::
841
841
<bar>1</bar>
842
842
</response>
843
843
844
- Be aware that this encoder will consider keys beginning with ``@ `` as attributes, and will use
845
- the key ``#comment `` for encoding XML comments::
844
+ The special ``# `` key can be used to define the data of a node::
845
+
846
+ ['foo' => ['@bar' => 'value', '#' => 'baz']];
847
+
848
+ // is encoded as follows:
849
+ // <?xml version="1.0"?>
850
+ // <response>
851
+ // <foo bar="value">
852
+ // baz
853
+ // </foo>
854
+ // </response>
855
+
856
+ Furthermore, keys beginning with ``@ `` will be considered attributes, and
857
+ the key ``#comment `` can be used for encoding XML comments::
846
858
847
859
$encoder = new XmlEncoder();
848
860
$encoder->encode([
@@ -869,6 +881,34 @@ always as a collection.
869
881
changed with the optional ``$encoderIgnoredNodeTypes `` argument of the
870
882
``XmlEncoder `` class constructor.
871
883
884
+ The ``XmlEncoder `` Context Options
885
+ ..................................
886
+
887
+ The ``encode() `` method defines a third optional parameter called ``context ``
888
+ which defines the configuration options for the XmlEncoder an associative array::
889
+
890
+ $xmlEncoder->encode($array, 'xml', $context);
891
+
892
+ These are the options available:
893
+
894
+ ``xml_format_output ``
895
+ If set to true, formats the generated XML with line breaks and indentation.
896
+
897
+ ``xml_version ``
898
+ Sets the XML version attribute (default: ``1.1 ``).
899
+
900
+ ``xml_encoding ``
901
+ Sets the XML encoding attribute (default: ``utf-8 ``).
902
+
903
+ ``xml_standalone ``
904
+ Adds standalone attribute in the generated XML (default: ``true ``).
905
+
906
+ ``xml_root_node_name ``
907
+ Sets the root node name (default: ``response ``).
908
+
909
+ ``remove_empty_tags ``
910
+ If set to true, removes all empty tags in the generated XML (default: ``false ``).
911
+
872
912
The ``YamlEncoder ``
873
913
~~~~~~~~~~~~~~~~~~~
874
914
@@ -1192,72 +1232,6 @@ you indicate that you're expecting an array instead of a single object::
1192
1232
$data = ...; // The serialized data from the previous example
1193
1233
$persons = $serializer->deserialize($data, 'Acme\Person[]', 'json');
1194
1234
1195
- The ``XmlEncoder ``
1196
- ------------------
1197
-
1198
- This encoder transforms arrays into XML and vice versa. For example, take an
1199
- object normalized as following::
1200
-
1201
- ['foo' => [1, 2], 'bar' => true];
1202
-
1203
- The ``XmlEncoder `` encodes this object as follows:
1204
-
1205
- .. code-block :: xml
1206
-
1207
- <?xml version =" 1.0" ?>
1208
- <response >
1209
- <foo >1</foo >
1210
- <foo >2</foo >
1211
- <bar >1</bar >
1212
- </response >
1213
-
1214
- The array keys beginning with ``@ `` are considered XML attributes::
1215
-
1216
- ['foo' => ['@bar' => 'value']];
1217
-
1218
- // is encoded as follows:
1219
- // <?xml version="1.0"?>
1220
- // <response>
1221
- // <foo bar="value"/>
1222
- // </response>
1223
-
1224
- Use the special ``# `` key to define the data of a node::
1225
-
1226
- ['foo' => ['@bar' => 'value', '#' => 'baz']];
1227
-
1228
- // is encoded as follows:
1229
- // <?xml version="1.0"?>
1230
- // <response>
1231
- // <foo bar="value">baz</foo>
1232
- // </response>
1233
-
1234
- Context
1235
- ~~~~~~~
1236
-
1237
- The ``encode() `` method defines a third optional parameter called ``context ``
1238
- which defines the configuration options for the XmlEncoder an associative array::
1239
-
1240
- $xmlEncoder->encode($array, 'xml', $context);
1241
-
1242
- These are the options available:
1243
-
1244
- ``xml_format_output ``
1245
- If set to true, formats the generated XML with line breaks and indentation.
1246
-
1247
- ``xml_version ``
1248
- Sets the XML version attribute (default: ``1.1 ``).
1249
-
1250
- ``xml_encoding ``
1251
- Sets the XML encoding attribute (default: ``utf-8 ``).
1252
-
1253
- ``xml_standalone ``
1254
- Adds standalone attribute in the generated XML (default: ``true ``).
1255
-
1256
- ``xml_root_node_name ``
1257
- Sets the root node name (default: ``response ``).
1258
-
1259
- ``remove_empty_tags ``
1260
- If set to true, removes all empty tags in the generated XML (default: ``false ``).
1261
1235
1262
1236
The ``CsvEncoder ``
1263
1237
------------------
0 commit comments