- Installation
Download bundle in src/Level42/TddBundle
or add in your composer.json file
"require": {
...
"level42/notjaxb-bundle": "1.3"
...
},
If you don't have Composer yet, download it following the instructions on http://getcomposer.org/.
- Overview
Any class that needs to be mapped to an XML document will need this annotation defined on the class level. Options :
- name : XML node name
- ns : XML Element namespace
XML
<product>
<.../>
</product>
PHP
/**
* @XmlObject([ns="http://...",] [name="product"])
*/
class Product
{
}
This annotation will map a class property to a node within the XML document. An element can be either a simple value node or a child node which maps to a child object. Options :
- name : Node name if different in XML
- type : Object type (fullclass path)
- ns : Element namespace
XML
<product>
<attribute></attribute>
</product>
PHP
/**
* @XmlElement([name="attribute",] [type="Namespace\Attribute"])
*/
private $attribute;
This annotation allows you to map collections of XML nodes to arrays of objects. Options :
- name : Node name if different in XML
- type : Object type (fullclass path)
- wrapper : Paren object name
- ns : Element namespace
XML
<product>
<attribute code="sku"></attribute>
<attribute code="short_description"></attribute>
</product>
PHP
/**
* @XmlList([name="attribute",] [wrapper="attributes",] [type="Namespace\Attribute"], [ns="http://..."])
*/
private $attributes;
This annotation will map a class property to an attribute within an XML node. Options :
- name : Attribute name in XML (if different of class attribute name)
- ns : Attribute namespace
XML
<product id="1">
< .../>
</product>
PHP
/**
* @XmlAttribute([name="id"])
*/
private $uniqueId;
This annotation will map the value of an XML node to a class property when the node is mapped to a class.
XML
<product id="1">
<description lang="fr">Description du produit en français</description>
</product>
PHP
/**
* @XmlValue
*/
private $description;
This annotation allows you to get a XML node as string. Options :
- name : Attribute name in XML (if different of class attribute name)
- ns : Attribute namespace
XML
<personne>
< .../>
</personne>
PHP
/**
* @XmlRaw (name="personne", [ns="http://..."])
*/
private $personne;
- To serialize an object to XML, use "notjaxb.xml_unmarshalling" service.
- To unserialize XML XML to object, use "notjaxb.xml_marshalling" service.
See https://github.com/Level42/NotJaxbBundle/tree/master/Tests/Entity
- Namespace support in XML serialization
- Add XSD Entity generator
- Add Json serializer/unserializer
Date : 2013-11-11 Fix marshalling bug PSR-0 problem out of Symfony2
Date : 2013-05-28 Fix namespace support on XmlElements
Date : 2013-04-06 Add XML serialization (without namespaces)
Date : 2013-03-29 Add multiple namespace support
Date : 2013-03-19 First stable version