Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit60c7657

Browse files
amoiraudjaviereguiluz
authored andcommitted
Add XmlEncoder documentation with $context available options
1 parent04af434 commit60c7657

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

‎components/serializer.rst‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,62 @@ you indicate that you're expecting an array instead of a single object.
856856
857857
$data = ...; // The serialized data from the previous example
858858
$persons = $serializer->deserialize($data, 'Acme\Person[]', 'json');
859+
860+
The ``XmlEncoder``
861+
-----------------------
862+
863+
This encoder transforms arrays into XML and vice versa.
864+
865+
For example, take an object normalized as following::
866+
867+
array('foo' => array(1, 2), 'bar' => true);
868+
869+
The ``XmlEncoder`` will encode this object like that::
870+
871+
<?xml version="1.0"?>
872+
<response>
873+
<foo>1</foo>
874+
<foo>2</foo>
875+
<bar>1</bar>
876+
</response>
877+
878+
Be aware that this encoder will consider keys beginning with ``@`` as attributes::
879+
880+
$encoder = new XmlEncoder();
881+
$encoder->encode(array('foo' => array('@bar' => 'value')));
882+
// will return:
883+
// <?xml version="1.0"?>
884+
// <response>
885+
// <foo bar="value" />
886+
// </response>
887+
888+
Context
889+
~~~~~~~~~~~~~~~
890+
891+
The context param is an array of additional options for the XmlEncoder.
892+
It must be defined in the call of XmlEncoder encode() method :
893+
894+
$xmlEncoder->encode($array, 'xml', $context);
895+
896+
**Available params :**
897+
898+
``xml_format_output``
899+
If setted to true, format the output XML with line break and indentation
900+
901+
``xml_version``
902+
Change the XML version attribute
903+
904+
``xml_encoding``
905+
Change the XML encoding attribute
906+
907+
``xml_standalone``
908+
Add standalone attribute in XML output
909+
910+
``remove_empty_tags``
911+
If setted to true, remove all empty tags in the XML output
912+
913+
``xml_root_node_name``
914+
Change the root node name (default : response)
859915

860916
Recursive Denormalization and Type Safety
861917
-----------------------------------------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp