-
Notifications
You must be signed in to change notification settings - Fork 44
Home
moyarada edited this page Aug 23, 2010
·
20 revisions
XSD to PHP is a set of classes which allow you to compile XSD schemas to PHP classes, marshal PHP classes to XML, and unmarshal XML to PHP classes.
- Compile XSD schemas to PHP models
- XML marshalling
- XML unmarshalling
- PHP 5.3 or higher, due to heavy use of PHP namespaces
- Create XSD schema from PHP classes
Compile schema
```php
use com\mikebevz\xsd2php;
$xsd2php = new xsd2php\Xsd2Php(“path/to/schema.xsd”);
$xsd2php→saveClasses(“path/to/generated/files”, true);
Second argument in saveClasses method defines whether create a directory if it doesn't exist.
See test/Xsd2PhpTest.php for examples.
h3. Marshalling XML
On example of UBL Order schema:
```php
use com\mikebevz\xsd2php;
use oasis\names\specification\ubl\schema\xsd\Order_2;
$order = new Order_2\Order(); // Generated PHP model
// set $order properties here
$php2xml = new xsd2php\Php2Xml();
$xml = $php2xml->getXml($order);
h3. Unmarshalling XML
Second argument in saveClasses method defines whether create a directory if it doesn't exist.
See test/Xsd2PhpTest.php for examples.
h3. Marshalling XML
On example of UBL Order schema:
```php
use com\mikebevz\xsd2php;
use oasis\names\specification\ubl\schema\xsd\Order_2;
$order = new Order_2\Order(); // Generated PHP model
// set $order properties here
$php2xml = new xsd2php\Php2Xml();
$xml = $php2xml->getXml($order);
```php
use com\mikebevz\xsd2php;
$xml = file_get_contents(‘path/to/your.xml’);
$model = new yourModel();
$bind = new xsd2php\Bind();
$myUnmarshalledModel = $bind→bindXml($xml, $model);
```
From command line
$ phpunit
will start all available tests.