xp-framework/rfc — Issue #40: Annotation-based XML marshalling/unmarshalling
Author: thekid
Created: 2011-10-17 15:44:34+00:00
State: closed

Scope of Change
====
A new API will be created to map XML to objects (and vice versa) by means
of annotations. Also, the package "xml.xp" will be deprecated.

Rationale
====
Be able to deserialize any XML document and serialize objects to any XML.

Functionality
====

1) Unmarshalling
----
Consider the following XML:

```

Open a file

```

This can be mapped to a dialog object by declarting the following class:

```php
id= $id;
}

#[@xmlfactory(element= '@id')]
function getId() {
return $this->id;
}

#[@xmlmapping(element= 'caption')]
function setCaption($caption) {
$this->caption= $caption;
}

#[@xmlfactory(element= 'caption')]
function getCaption() {
return $this->caption;
}
}
?>
```

...and using the following script:

```php

```

2) Marshalling
----
Assuming we've declared the class as above, the following sourcecode will
create XML from the object:

```php
setId('file.open');
$dialog->setCaption('Open a file');

$xml= Marshaller::marshal($dialog);
echo 'Marshalled object= ', xp::stringOf($xml);
?>
```

Security considerations
====
n/a

Speed impact
====
n/a

Dependencies
====
n/a

Related documents
====
- Castor
http://castor.org/xml-mapping.html

- PHP 5 version
http://xp-framework.info/xml/xp.en_US/news/view?10