Я написал простую и основанную на аннотациях PAXB: https://github.com/ziollek/PAXB. Проверьте, достаточно ли этого решения.
Примеры классов с аннотациями привязки XML
/**
* @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;
}
}
Пример сортировки:
$sampleEntity = new SampleEntity(
array(1,2,3),
new AttributeValueEntity('sample attribure', 'sample value'),
'Sample text'
);
echo PAXB\Setup::getMarshaller()->marshall($sampleEntity, true);
и вывод:
<?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>
Демаршаллизация
$xmlInput = '...'; //as above
/** @var SampleEntity $sampleEntity */
$sampleEntity = PAXB\Setup::getUnmarshaller()->unmarshall($xmlInput, 'SampleEntity');