File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -1097,6 +1097,29 @@ the key ``#comment`` can be used for encoding XML comments::
1097
1097
You can pass the context key ``as_collection `` in order to have the results
1098
1098
always as a collection.
1099
1099
1100
+ .. note ::
1101
+
1102
+ You may need to add some attributes on the root node. This can be done this way :
1103
+
1104
+ .. code-block :: php
1105
+ <?php
1106
+ $encoder = new XmlEncoder();
1107
+ $encoder->encode([
1108
+ '@attribute1' => 'foo',
1109
+ '@attribute2' => 'bar',
1110
+ '#' => ['foo' => ['@bar' => 'value', '#' => 'baz']]
1111
+ ], 'xml');
1112
+
1113
+ This will generate the following XML :
1114
+
1115
+ .. code-block :: xml
1116
+ <?xml version =" 1.0" ?>
1117
+ <response attribute1 =" foo" attribute2 =" bar" >
1118
+ <foo bar =" value" >
1119
+ baz
1120
+ </foo >
1121
+ </response >
1122
+
1100
1123
.. tip ::
1101
1124
1102
1125
XML comments are ignored by default when decoding contents, but this
You can’t perform that action at this time.
0 commit comments