Posts Tagged ‘XML’

A new XmlObject

Sunday, April 15th, 2007

I’ve become somewhat addicted to the SqlObject stuff in TurboGears. After reading and reading my book (and finishing my first skim through) I was left with an appetite to put it to good use. Obviously theres Conduit.net. But I ended up thinking about the state of the data types in conduit. I remember implementing the contact datatype, and it’s always been in a pretty sorry state. Your best hope for working with the data was to directly work with self.vObject, which I have zero-understanding of. On top of that, we want to use the OpenSync XML schemas in Conduit to aid interoperability with it, SynCE and to help with any networking layers we add (Conduit-web, Avahi/Twisted).

Could there possibly be an SqlObject equivalent for Xml? At first glance, yes and no. XMLObject would seem to be dead? You have to craft a parser, and there seems to be a compilation step. Another XMLObject seems better. It doesn’t seem to have the magic glue that SQLObject does, and you don’t seem to be able to create your own “model objects”. EaseXML is the closest to what I want, but it too seems dead?

Anyway, at the moment I am hacking away on my own implementation as bit of a learning tool. I’ve implemented the latest OpenSync Note schema in my objects and have something that looks like this:

class Note(xmlobject.XmlObject):
Body = MultiText(maxOccurs=1, minOccurs=1)
Categories = Categories(maxOccurs=1, minOccurs=0)
Class = Class()
DateCreated = DateTimeContent()
LastModified = DateTimeContent()
Summary = MultiText()
XIrmcLuid = StringContent()

And am able to produce some dummy output using Note().get_xml()

<Note>
<Body Language="Language" AlternativeTextRep="AlternativeTextRep">
<Content>Content</Content>
</Body>
<LastModified TimezoneID="TimezoneID" DateValue="DateValue">
<Content>Content</Content>
</LastModified>
<Summary Language="Language" AlternativeTextRep="AlternativeTextRep">
<Content>Content</Content>
</Summary>
<XIrmcLuid>
<Content>Content</Content>
</XIrmcLuid>
<DateCreated TimezoneID="TimezoneID" DateValue="DateValue">
<Content>Content</Content>
</DateCreated>
<Class>
<ClassValue>ClassValue</ClassValue>
</Class>
<Categories>
<Category>Category</Category>
</Categories>
</Note>

It’s all pretty dirty and basic right now. But it’s going pretty well.