[XML-SIG] xmlpickle.py ?!

Mike Olson Mike.Olson@fourthought.com
Mon, 07 Aug 2000 09:36:59 -0600


"M.-A. Lemburg" wrote:
> 

You may want to look at Zope in Zope/lib/python/ZODB/ImportExport.py. 
they do some XML pickling here.  However, I think they call back to each
object for help in the pickle processes (each object writes thier own
chunk of XML).  Though I'm not 100% sure.

Mike



> I'm currently looking into writing a xmlpickle.py module
> with the intent to be able to pickle (and unpickle) arbitrary
> Python objects in a way that makes the objects editable through
> a XML editor or convertible to some other format using the
> existing XML tools.
> 
> After looking at the archives of this SIG, I found that the
> idea was already tossed around a few times, but I couldn't
> find any downloadble outcome.
> 
> I've looked at pickle.py a bit and realized that the extensible
> nature of the pickle mechanism would probably cause trouble
> because the DTD would have to be generated as well (not a good
> idea). There are two alternatives to this though:
> 
> 1. add an element which handles all non-core Python object
>    types (the ones registered through copy_reg)
> 
> 2. use an abstract DTD altogheter
> 
> Example for 1:
> 
> <PythonPickle version="1.0">
> <Dictionary>
>         <String name="aString">abcdef</String>
>         <List name="aList">
>                 <Integer>10</Integer>
>                 <String>abc</String>
>         </List>
>         <Instance name="aInstance" module="test" classname="test">
>                 <String name="instvar">value</String>
>         </Instance>
>         <Object name="myObject" constructor="mx.DateTime.DateTime">
>                 <Tuple>
>                         <Integer>2000</Integer>
>                         <Integer>8</Integer>
>                         <Integer>6</Integer>
>                 </Tuple>
>         </Object>
> </Dictionary>
> </PythonPickle>
> 
> Example for 2:
> 
> <PythonPickle version="1.0">
> <Object type="dictionary">
>         <Object name="aString" type="string">abcdef</Object>
>         <Object name="aList" type="list">
>                 <Object type="integer">10</Object>
>                 <Object type="string">abc</Object>
>         </Object>
>         <Object name="aInstance" type="instance" module="test" classname="test">
>                 <Object name="instvar" type="string">value</Object>
>         </Object>
>         <Object name="myObject" type="datetime">
>                 <Object type="tuple">
>                         <Object type="integer">2000</Object>
>                         <Object type="integer">8</Object>
>                         <Object type="integer">6</Object>
>                 </Object>
>         </Object>
> </Object>
> </PythonPickle>
> 
> Variant 1 has the nice feature of making the basic Python
> explicit and the DTD could also carry some context sensitive
> information. Variant 2 is much easier to extend and has
> a very simple DTD, but conversion tools would have to know
> much about the mechanism behind it to generate correct
> documents.
> 
> BTW, I'm very new to XML... what's the general rule in XML
> on where to put the object value ? ... into an attribute
> or the tag content ?
> 
> Thoughts ?
> 
> Thanks,
> --
> Marc-Andre Lemburg
> ______________________________________________________________________
> Business:                                      http://www.lemburg.com/
> Python Pages:                           http://www.lemburg.com/python/
> 
> _______________________________________________
> XML-SIG maillist  -  XML-SIG@python.org
> http://www.python.org/mailman/listinfo/xml-sig

-- 
Mike Olson				 Principal Consultant
mike.olson@fourthought.com               (303)583-9900 x 102
Fourthought, Inc.                         http://Fourthought.com 
Software-engineering, knowledge-management, XML, CORBA, Linux, Python