[XML-SIG] Schema -> Python Objects framework?

Ian Sparks ians@etrials.com
Fri, 24 May 2002 09:06:29 -0400


I have on occasion found myself writing python classes with the ability to
read and write themselves to XML :

class x:
    def toxml(self):
        return '<x att1="%s" att2="%s"/>' %
(xmlencode(self.att1),xmlencode(self.att2))
    def fromxml(self,element):
        self.att1 = element.getAttribute('att1')
        ...

Sometimes this is more useful than using a DOM directly (for instance, where
you want to keep memory usage low).

It occurs to me that it might be fairly easy to write some code that would
take an XML Schema and convert it into skeleton python classes with these
toXML() and fromXML() methods auto-generated.

This then begs the question : Has anyone done this?

- Ian Sparks.