xml marshal of general (but non Python standard) class

syd syd.diamond at gmail.com
Wed Mar 23 14:00:39 EST 2005


Hello all,

In my project, I have container classes holding lists of item classes.
For example, a container class myLibrary might hold a list of item
classes myNation and associated variables like myNation.name='USA' and
myNation.continent='North America'.

Bottom line, I was hoping to use this structure to marshal the classes
to xml.

However, I've got dozens of unique classes (all subclassing the
container and item classes) with unique variables attached, and I do
not want to write rules for each.

I was looking at the source for generic in xml.marshal (from
xml.marshal import generic) which will dump to xml any configuration of
standard Python data types, for example, a tuple of dictionaries
containing lists of strings.  This source just writes a rule for each
data type.

Naively, I would hope that there'd be something where the marshaller
could just look at my data class, see what variables were associated,
and just go from there.

I'm moderately experienced with Python, but by no means an expert, and
I'm not an xml pro, either.  Would this project (xml marshal of a new
class) be worth my time?  If so, what would be best way to proceed?
Any other thoughts?

>>> import xml.marshal
>>> from xml.marshal import generic
>>> generic.dumps(['thank you','comp.lang.python'])
'<?xml version="1.0"?><marshal><list id="i2"><string>thank
you</string><string>comp.lang.python</string></list></marshal>




More information about the Python-list mailing list