The xobj project provides an object reflector between various dynamic languages and XML. Currently, python and ActionScript 3 implementations are available.
The source tree is available as a Mercurial repository at http://hg.rpath.com/xobj/
Motivationsxobj was motivated by a few specific goals:
Make the use of XML for object model interchange between client and server tiers less painful Allow your code to use real typed instances of classes rather than simple generic data structures Treat your code as the definition of schema rather than forcing an XMLSchema driven approach on your code. Read and write XML documents that will pass most XMLSchema structural validation requirements with relatively little effort on your part It is not required to provide an XML schema to use xobj. Custom objects may be used for parts or all of the document, whether or not an XML schema is provided. Schema validation is optional. If new elements show up, they will be preserved across read/write; schema additions will not normally require code changes.
Implementation NotesDuring XML decoding, xobj preserves namespaces, element ordering and tracks attributes vs elements so that re-encoded object graphs can comply with most of the common XMLSchema validation requirements. This observed metadata is attached to your object graph rather than hidden out of view.
For "whole cloth" generation of XML from object graphs that were not themselves decoded in the first place, you can provide the namespace, elements ordering and attribute metadata declaratively to facilitate XMLSchema conformance.
During decoding, xobj uses both the runtime type information available from your classes as well as a typemap you specify to determine the target type for every decoded XML element.
During encoding, xobj uses this same runtime information plus additional observed (or provided) metadata to inform the output XML.
For ActionScript, xobj decodes XML documents directly into typed instance objects rather than generic Object or ObjectProxy wrappers. This avoids the double-handling of generic objects required by the default SimpleXMLDecoder provided by Adobe Flex.
ExamplesFor example, using the ElementTree Python library, you might write something like this:
imageItem = x for x in parent if x.tag='image'
In this case, imageItem will always be a list, even if it is not defined in the XML schema to be a sequence.
Using xobj, you could refer to the image element more directly:
That will be either a single item or a list, depending on the context. Additionally, the image object will be of a class you specify.
The unit test cases provide further examples of usage and intended semantics of the xobj methods.