-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add documentation for XmlEncoder context param #7231
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
Changes from 5 commits
a363950
7d4da29
b09a22d
0feac81
0d8e764
4d6281e
7057482
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -674,6 +674,63 @@ you indicate that you're expecting an array instead of a single object. | |
|
||
$data = ...; // The serialized data from the previous example | ||
$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:: | ||
|
||
array('foo' => array(1, 2), 'bar' => true); | ||
|
||
The ``XmlEncoder`` encodes this object as follows: | ||
|
||
.. code-block:: xml | ||
|
||
<?xml version="1.0"?> | ||
<response> | ||
<foo>1</foo> | ||
<foo>2</foo> | ||
<bar>1</bar> | ||
</response> | ||
|
||
The array keys beginning with ``@`` are considered XML attributes:: | ||
|
||
$encoder = new XmlEncoder(); | ||
$encoder->encode(array('foo' => array('@bar' => 'value'))); | ||
// will return: | ||
// <?xml version="1.0"?> | ||
// <response> | ||
// <foo bar="value" /> | ||
// </response> | ||
|
||
Context | ||
~~~~~~~ | ||
|
||
The XmlEncoder ``encode()`` method defines a third optional parameter called | ||
``context`` to define soem configuration options for the XmlEncoder:: | ||
|
||
$xmlEncoder->encode($array, 'xml', $context); | ||
|
||
These are the options available: | ||
|
||
``xml_format_output`` | ||
If set to true, format the output XML with line breaks and indentation. | ||
|
||
``xml_version`` | ||
Change the XML version attribute. | ||
|
||
``xml_encoding`` | ||
Change the XML encoding attribute. | ||
|
||
``xml_standalone`` | ||
Add standalone attribute in XML output . | ||
|
||
``xml_root_node_name`` | ||
Change the root node name (default: ``response``). | ||
|
||
``remove_empty_tags`` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). |
||
If set to true, remove all empty tags in the XML output. | ||
|
||
Learn more | ||
---------- | ||
|
There was a problem hiding this comment.
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)