[Zope] - xml marshaling experiment
Amos Latteier
amos@aracnet.com
Sat, 23 Jan 1999 14:01:05 -0800
With all this talk of xml-rpc integration into ZPublisher, I just had a
small idea. Why not add simple xml marshalling as a Zope input marshalling
format. As an experiment I chose Andrew K's xml.marshal, though of course,
we could add any or all the other xml marshalling formats as well.
Here's the patch for ZPublisher/Converters.py:
*** Converters.py Sat Jan 23 13:29:38 1999
--- Converters.py Sat Jan 23 13:19:58 1999
***************
*** 159,164 ****
--- 159,168 ----
if type(v) is not ListType: v=(v,)
return tuple(v)
+ def field2xmlmarshal(v):
+ import xml.marshal
+ return xml.marshal.loads(v)
+
type_converters = {
'float': field2float,
'int': field2int,
***************
*** 171,175 ****
--- 175,180 ----
'tokens': field2tokens,
'lines': field2lines,
'text': field2text,
+ 'xmlmarshal': field2xmlmarshal,
}
The only thing that's required is to add the xml sig's xml package to some
place Zope can get at, like lib/python1.5 (hopefully the xml package will
be in Zope by default in the next release) and of course get the
xml-marshal module (which I believe was posted to the xml sig a while ago.)
Voila--now you can enter xml into form elements and have Zope parse it,
simply by naming your form elements with the 'xmlmarshal' type converter,
for example, 'myInput:xmlmarshal'. Here's a Document that allows you to
experiment:
<h1>XML Marshal Demo</h1>
<form action="<!--var id-->" method="post">
<textarea name="spam:xmlmarshal" cols="60" rows="5">
</textarea><br>
<input type="submit">
</form>
<!--#if spam-->
spam=<!--#var spam-->
<!--#/if-->
This document calls itself and displays the marshalled contents of the
textarea. So if you type this into the textarea:
<marshal><tuple><integer>12</integer><string>sdsdf</string></tuple></marshal>
You'll see this:
spam=(12, 'sdsdf')
So, I guess you probably won't be entering a lot of this stuff by hand ;-)
But maybe it would be a nice format for cookies, or Zope properties, or for
programs that call Zope methods (oh, I guess that's what xml-rpc is for...)
etc.
-Amos