Download the PHP package yuubit/paxb without Composer
On this page you can find all versions of the php package yuubit/paxb. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Vendor yuubit
Package paxb
Short Description Public library PAXB - PHP Annotation Xml Binding, basic implementation of annotation driven xml binding
License MIT
Package paxb
Short Description Public library PAXB - PHP Annotation Xml Binding, basic implementation of annotation driven xml binding
License MIT
Please rate this library. Is it a good library?
Informations about the package paxb
PAXB
PAXB - very basic implementation of annotation driven xml binding
Supported annotations
This lib supports listed bellow annotations:
- XmlAttribute(name="")
- XmlElement(name="", type="") - type is required for unmarshaling fields containing objects
- XmlElementWrapper(name) - name required
- XmlTransient
- XmlValue
These annotations could be used only as property annotations or class annotation(XmlElement only)
Sample code
Marshalling example
/**
* @XmlElement(name="root")
*/
class SampleEntity {
/**
* @XmlElement(name="attribute-value", type="AttributeValueEntity")
*/
private $nestedEntity;
private $text;
/**
* @XmlElementWrapper(name="number-list")
*/
private $number = array();
public function __construct($number = array(), $nestedEntity = null, $text = "")
{
$this->number = $number;
$this->nestedEntity = $nestedEntity;
$this->text = $text;
}
}
class AttributeValueEntity {
/**
* @XmlAttribute
*/
private $attribute;
/**
* @XmlElement
*/
private $value;
/**
* @param string $attribute
* @param string $value
*/
public function __construct($attribute = "", $value = "")
{
$this->attribute = $attribute;
$this->value = $value;
}
/**
* @return string
*/
public function getAttribute()
{
return $this->attribute;
}
/**
* @return string
*/
public function getValue()
{
return $this->value;
}
}
Marshalling code:
$sampleEntity = new SampleEntity(
array(1,2,3),
new AttributeValueEntity('sample attribure', 'sample value'),
'Sample text'
);
echo PAXB\Setup::getMarshaller()->marshall($sampleEntity, true);
Output:
<?xml version="1.0"?>
<root>
<attribute-value attribute="sample attribure">
<value>sample value</value>
</attribute-value>
<text>Sample text</text>
<number-list>
<number>1</number>
<number>2</number>
<number>3</number>
</number-list>
</root>
Unmarshalling example
$xmlInput = '...'; //as above
/** @var SampleEntity $sampleEntity */
$sampleEntity = PAXB\Setup::getUnmarshaller()->unmarshall($xmlInput, 'SampleEntity');
Running examples
- Install composer: php -r "eval('?>'.file_get_contents('https://getcomposer.org/installer'));"
- Install dependencies: ./composer.phar install
- run demo script: php demo/demo-marshall.php or php demo/demo-unmarshall.php
All versions of paxb with dependencies
PHP Build Version
Package Version
Requires
doctrine/annotations Version
1.6.*
The package yuubit/paxb contains the following files
Loading the files please wait ....