[XML-SIG] xmlpickle.py ?!

M.-A. Lemburg mal@lemburg.com
Mon, 07 Aug 2000 15:49:44 +0200

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">
	<String name="aString">abcdef</String>
	<List name="aList">
        <Instance name="aInstance" module="test" classname="test">
        	<String name="instvar">value</String>
	<Object name="myObject" constructor="mx.DateTime.DateTime">

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 name="aInstance" type="instance" module="test" classname="test">
        	<Object name="instvar" type="string">value</Object>
	<Object name="myObject" type="datetime">
		<Object type="tuple">
	               	<Object type="integer">2000</Object>
        	       	<Object type="integer">8</Object>
               		<Object type="integer">6</Object>

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

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 ?

Marc-Andre Lemburg
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/