Skip to content
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

Add XmlNamespace annotation documentation #213

Merged
merged 1 commit into from
Jan 13, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
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
56 changes: 52 additions & 4 deletions doc/reference/annotations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ the method should appear like a property of the object.
deserialization.

@Inline
~~~~~~~~
~~~~~~~
This annotation can be defined on a property to indicate that the data of the property
should be inlined.

Expand Down Expand Up @@ -512,18 +512,22 @@ Resulting XML:
<result name="firstname" value="Adrien"/>

@XmlElement
~~~~~~~~
~~~~~~~~~~~
This annotation can be defined on a property to add additional xml serialization/deserialization properties.

.. code-block :: php

<?php

use JMS\Serializer\Annotation\XmlElement;

/**
* @XmlNamespace(uri="http://www.w3.org/2005/Atom", prefix="atom")
*/
class User
{
/**
* @XmlElement(cdata=false)
* @XmlElement(cdata=false, namespace="http://www.w3.org/2005/Atom")
*/
private $id = 'my_id;
}
Expand All @@ -532,4 +536,48 @@ Resulting XML:

.. code-block :: xml

<id>my_id</id>
<atom:id>my_id</atom:id>

@XmlNamespace
~~~~~~~~~~~~~
This annotation allows you to specify Xml namespace/s and prefix used.

.. code-block :: php

<?php

use JMS\Serializer\Annotation\XmlNamespace;

/**
* @XmlNamespace(uri="http://example.com/namespace")
* @XmlNamespace(uri="http://www.w3.org/2005/Atom", prefix="atom")
*/
class BlogPost
{
/**
* @Type("JMS\Serializer\Tests\Fixtures\Author")
* @Groups({"post"})
* @XmlElement(namespace="http://www.w3.org/2005/Atom")
*/
private $author;
}

class Author
{
/**
* @Type("string")
* @SerializedName("full_name")
*/
private $name;
}

Resulting XML:

.. code-block :: xml

<?xml version="1.0" encoding="UTF-8"?>
<blog-post xmlns="http://example.com/namespace" xmlns:atom="http://www.w3.org/2005/Atom">
<atom:author>
<full_name><![CDATA[Foo Bar]]></full_name>
</atom:author>
</blog>
2 changes: 2 additions & 0 deletions doc/reference/xml_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ XML Reference
<class name="Fully\Qualified\ClassName" exclusion-policy="ALL" xml-root-name="foo-bar" exclude="true"
accessor-order="custom" custom-accessor-order="propertyName1,propertyName2,...,propertyNameN"
access-type="public_method" discriminator-field-name="type">
<xml-namespace prefix="atom" uri="http://www.w3.org/2005/Atom"/>
<discriminator-class value="some-value">ClassName</discriminator-class>
<property name="some-property"
exclude="true"
Expand All @@ -26,6 +27,7 @@ XML Reference
xml-key-value-pairs="true"
xml-attribute-map="true"
max-depth="2"
xml-namespace="http://www.w3.org/2005/Atom"
>
<!-- You can also specify the type as element which is necessary if
your type contains "<" or ">" characters. -->
Expand Down
3 changes: 3 additions & 0 deletions doc/reference/yml_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ YAML Reference
some-value: ClassName
virtual_properties:
getSomeProperty: {}
xml_namespaces:
atom: http://www.w3.org/2005/Atom
properties:
some-property:
exclude: true
Expand Down Expand Up @@ -45,6 +47,7 @@ YAML Reference
xml_element:
cdata: false
max_depth: 2
xml_namespace: http://www.w3.org/2005/Atom

handler_callbacks:
serialization:
Expand Down