I have just uploaded a PHP library for importing and exporting OpenDD documents. It is version 0.1 so it is still very much under development, but it should still be usable.
Import example
The import function accepts an OpenDD XML document and returns an ODDDocument
object, which can then be iterated through to obtain access to the ODD*
classes.
The XML file:
<odd version="1.0" generated="Fri, 09 May 2008 18:53:37 +0100">
<entity uuid="http://www.example.com/a" class="foo" subclass="http://www.example.com/b" />
<metadata uuid="http://www.example.com/c" entity_uuid="http://www.example.com/a" name="Squid" >paper</metadata>
<relationship uuid1="http://www.example.com/a" type="hates" uuid2="http://www.example.com/b" />
</odd>
Example code to process it:
$doc = ODD_Import($in);
foreach ($doc as $element)
print_r($element); // Just echo, but you should probably do something meaningful.
Export example
Export involves constructing an ODDDocument
object and populating it with various classes, each one representing one of the OpenDD elements.
This object is then serialised.
Here is some example code:
$out = new ODDDocument(); // Create new document
$entity = new ODDEntity("http://www.example.com/a", "foo", "http://www.example.com/b");
$out->addElement($entity);
$meta = new ODDMetaData("http://www.example.com/c", "http://www.example.com/a", "Squid", "paper");
$out->addElement($meta);
$rel = new ODDRelationship("http://www.example.com/a", "hates", "http://www.example.com/b");
$out->addElement($rel);
echo ODD_Export($out); // Export
When I get a chance I’ll upload some libraries in other languages, but if you feel inclined then feel free to implement your own!