Skip to content

Commit aa1aac0

Browse files
committed
Merge branch '6.4' into 7.0
* 6.4: Adding precision on how to define attributes on the root node for the XML Encoder
2 parents 458674f + 289d1ef commit aa1aac0

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

components/serializer.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,23 @@ the key ``#comment`` can be used for encoding XML comments::
10991099
You can pass the context key ``as_collection`` in order to have the results
11001100
always as a collection.
11011101

1102+
.. note::
1103+
1104+
You may need to add some attributes on the root node::
1105+
1106+
$encoder = new XmlEncoder();
1107+
$encoder->encode([
1108+
'@attribute1' => 'foo',
1109+
'@attribute2' => 'bar',
1110+
'#' => ['foo' => ['@bar' => 'value', '#' => 'baz']]
1111+
], 'xml');
1112+
1113+
// will return:
1114+
// <?xml version="1.0"?>
1115+
// <response attribute1="foo" attribute2="bar">
1116+
// <foo bar="value">baz</foo>
1117+
// </response>
1118+
11021119
.. tip::
11031120

11041121
XML comments are ignored by default when decoding contents, but this

0 commit comments

Comments
 (0)