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

Commitaa036af

Browse files
committed
minor#7231 Add documentation for XmlEncoder context param (amoiraud, javiereguiluz)
This PR was submitted for the master branch but it was merged into the 3.3 branch instead (closes#7231).Discussion----------Add documentation for XmlEncoder context paramAdd documentation for XmlEncoder context paramRelated to :symfony/symfony#20524Thisfixes#7227Commits-------5e23045 Minor tweaksadbc7b2 Minor rewords2dc6ed3 Minor syntax issue6050370 Minor syntax issues and some rewordings2f3cf02 Correcting my bad english with a bilingual friend60c7657 Add XmlEncoder documentation with $context available options04af434 erratumc83e59d Add XmlEncoder documentation with $context available options
2 parents8bfd254 +5e23045 commitaa036af

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

‎components/serializer.rst‎

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,63 @@ you indicate that you're expecting an array instead of a single object.
857857
$data = ...; // The serialized data from the previous example
858858
$persons = $serializer->deserialize($data, 'Acme\Person[]', 'json');
859859
860+
The ``XmlEncoder``
861+
------------------
862+
863+
This encoder transforms arrays into XML and vice versa. For example, take an
864+
object normalized as following::
865+
866+
array('foo' => array(1, 2), 'bar' => true);
867+
868+
The ``XmlEncoder`` encodes this object as follows:
869+
870+
..code-block::xml
871+
872+
<?xml version="1.0"?>
873+
<response>
874+
<foo>1</foo>
875+
<foo>2</foo>
876+
<bar>1</bar>
877+
</response>
878+
879+
The array keys beginning with ``@`` are considered XML attributes::
880+
881+
array('foo' => array('@bar' => 'value'));
882+
883+
// is encoded as follows:
884+
// <?xml version="1.0"?>
885+
// <response>
886+
// <foo bar="value" />
887+
// </response>
888+
889+
Context
890+
~~~~~~~
891+
892+
The ``encode()`` method defines a third optional parameter called ``context``
893+
which defines the configuration options for the XmlEncoder an associative array::
894+
895+
$xmlEncoder->encode($array, 'xml', $context);
896+
897+
These are the options available:
898+
899+
``xml_format_output``
900+
If set to true, formats the generated XML with line breaks and indentation.
901+
902+
``xml_version``
903+
Sets the XML version attribute (default: ``1.1``).
904+
905+
``xml_encoding``
906+
Sets the XML encoding attribute (default: ``utf-8``).
907+
908+
``xml_standalone``
909+
Adds standalone attribute in the generated XML (default: ``true``).
910+
911+
``xml_root_node_name``
912+
Sets the root node name (default: ``response``).
913+
914+
``remove_empty_tags``
915+
If set to true, removes all empty tags in the generated XML.
916+
860917
Recursive Denormalization and Type Safety
861918
-----------------------------------------
862919

@@ -924,6 +981,47 @@ When a ``PropertyTypeExtractor`` is available, the normalizer will also check th
924981
matches the type of the property (even for primitive types). For instance, if a ``string`` is provided, but
925982
the type of the property is ``int``, an:class:`Symfony\\Component\\Serializer\\Exception\\UnexpectedValueException`
926983
will be thrown.
984+
=======
985+
986+
=======
987+
988+
>>>>>>> Minor rewords
989+
Context
990+
~~~~~~~
991+
992+
The ``encode()`` method defines a third optional parameter called ``context``
993+
which defines the configuration options for the XmlEncoder an associative array::
994+
995+
$xmlEncoder->encode($array, 'xml', $context);
996+
997+
These are the options available:
998+
<<<<<<< HEAD
999+
1000+
=======
1001+
1002+
>>>>>>> Minor rewords
1003+
``xml_format_output``
1004+
If set to true, formats the generated XML with line breaks and indentation.
1005+
1006+
``xml_version``
1007+
Sets the XML version attribute (default: ``1.1``).
1008+
1009+
``xml_encoding``
1010+
Sets the XML encoding attribute (default: ``utf-8``).
1011+
1012+
``xml_standalone``
1013+
Adds standalone attribute in the generated XML (default: ``true``).
1014+
1015+
``xml_root_node_name``
1016+
  Sets the root node name (default: ``response``).
1017+
1018+
``remove_empty_tags``
1019+
<<<<<<< HEAD
1020+
If set to true, remove all empty tags in the XML output.
1021+
>>>>>>> Minor syntax issues and some rewordings
1022+
=======
1023+
If set to true, removes all empty tags in the generated XML.
1024+
>>>>>>> Minor rewords
9271025

9281026
Learn more
9291027
----------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp