8000 Add documentation for XmlEncoder context param by amoiraud · Pull Request #7231 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

Add documentation for XmlEncoder context param #7231

< 8000 div class="d-flex flex-order-2 flex-md-order-1 mx-2">
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Minor syntax issues and some rewordings
  • Loading branch information
javiereguiluz authored Dec 8, 2016
commit 0d8e7645779beffaa79d1a31ded5c21534eb0bb2
36 changes: 18 additions & 18 deletions components/serializer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -676,15 +676,16 @@ you indicate that you're expecting an array instead of a single object.
$persons = $serializer->deserialize($data, 'Acme\Person[]', 'json');

The ``XmlEncoder``
-----------------------

This encoder transforms arrays into XML and vice versa.
------------------

For example, take an object normalized as following::
This encoder transforms arrays into XML and vice versa. For example, take an
object normalized as following::

array('foo' => array(1, 2), 'bar' => true);

The ``XmlEncoder`` will encode this object like that::
The ``XmlEncoder`` encodes this object as follows:

.. code-block:: xml

<?xml version="1.0"?>
<response>
Expand All @@ -693,7 +694,7 @@ The ``XmlEncoder`` will encode this object like that::
<bar>1</bar>
</response>

Be aware that this encoder will consider keys beginning with ``@`` as attributes::
The array keys beginning with ``@`` are considered XML attributes::

$encoder = new XmlEncoder();
$encoder->encode(array('foo' => array('@bar' => 'value')));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the XmlEncoder class won't be called directly. It will be called when using $serializer->serialize($data, 'xml', $context)

Expand All @@ -704,33 +705,32 @@ Be aware that this encoder will consider keys beginning with ``@`` as attributes
// </response>

Context
~~~~~~~~~~~~~~~

The context param is an array of additional options for the XmlEncoder.
~~~~~~~

It must be defined while calling the XmlEncoder encode() method :
The XmlEncoder ``encode()`` method defines a third optional parameter called
``context`` to define soem configuration options for the XmlEncoder::

$xmlEncoder->encode($array, 'xml', $context);
$xmlEncoder->encode($array, 'xml', $context);

**Available params :**
These are the options available:

``xml_format_output``
If set to true, format the output XML with line break and indentation
If set to true, format the output XML with line breaks and indentation.

``xml_version``
Change the XML version attribute
Change the XML version attribute.

``xml_encoding``
Change the XML encoding attribute
Change the XML encoding attribute.

``xml_standalone``
Add standalone attribute in XML output
Add standalone attribute in XML output .

``xml_root_node_name``
Change the root node name (default : response)
  Change the root node name (default: ``response``).

``remove_empty_tags``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Context options related to the XML encoder should not be documented in the main chapter of the serializer doc IMO (but this should be decided by the doc team).
And if we document them (which is a good idea), context options supported by encoders for other formats should be documented too.

If set to true, remove all empty tags in the XML output
If set to true, remove all empty tags in the XML output.

Learn more
----------
Expand Down
0