[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">
<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/