XML Pickler?

Martin v. Loewis martin at v.loewis.de
Sat Jan 5 03:09:19 EST 2002


candiazoo at mediaone.net (Zoo Keeper) writes:

> This might sound like a crazy question... but has anyone written a
> "Pickle" module that (sort of) converts a class to XML?  Or at least
> the class data?

Sure, just use PyXML's xml.marshal.generic

>>> class X:pass
...
>>> x=X()
>>> x.a = 1
>>> x.b = ['empty']
>>> from xml.marshal import generic
>>> print generic.dumps(x)
<?xml version="1.0"?><marshal><object id="i2" module="__main__" class="X"><tuple></tuple><dictionary id="i3"><string>a</string><int>1</int><string>b</string><list id="i4"><string>empty</string></list></dictionary></object></marshal>

Or did you really mean "a class" instead of "an instance"?

Regards,
Martin



More information about the Python-list mailing list