Explorar o código

Add XmlNamespace annotation documentation

Eugene Serkin %!s(int64=11) %!d(string=hai) anos
pai
achega
1272ab57fb

+ 52 - 4
doc/reference/annotations.rst

@@ -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.
 
@@ -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;
     }
@@ -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 - 0
doc/reference/xml_reference.rst

@@ -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"
@@ -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. -->

+ 3 - 0
doc/reference/yml_reference.rst

@@ -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
@@ -45,6 +47,7 @@ YAML Reference
                 xml_element:
                     cdata: false
                 max_depth: 2
+                xml_namespace: http://www.w3.org/2005/Atom
 
         handler_callbacks:
             serialization: