monkinetic weblog

Steve Ivy's Weblog - Since 1999 - XII Ed.

Generating Python From XML Schema

I've been toying with the idea of writing a python library for Apple's Keynote file format, APXL.

After slogging through 4 objects and realizing that to do it right was going to be a LONG process, I started looking around for code generators that might read an XML Schema (which Apple provides for APXL – see the above link) and spit out python code.

Well, here it is: generateDS – generate data structures from XSL.

It seems fast enough, though I've had to hack it a good bit to work around Apple's element names, many of which have dashes in them (ie, 'font-styling','outlined-drawable-style-type') and are not valid python identifier names. So I had to add a function to remove the dashes and camelCase them, then make sure that the code calls my function every time it uses the name. I also modifed it to not put "get" in front of get accessors, but that's personal preference.

Still, it spits out 3500 lines of python in about .75 seconds. Once I've got it tweaked and played around with it some, I'll post the code.

My name is Steve Ivy and I write about technology, the open web, social software, and general nerdity on monkinetic.com. You should follow me on Twitter or subscribe to this blog if you like what you're reading. I spend my days hacking Movable Type, python, Django, and various other efforts at Wallrazer. This is my personal site.