[Zope3-dev] xml import / export in z2 & z3

Jean-Marc Orliaguet jmo at ita.chalmers.se
Wed Dec 7 09:33:46 EST 2005


Martijn Faassen wrote:

> Andreas Jung wrote:
>
>>> I'm about to write an xml importer for importing simple data 
>>> (properties,
>>> dictionaries). Exporting is easy, importing is trickier because a 
>>> parser
>>> is required.
>>>
>>> Is there any prefered framework for doing such things in zope3 (zope2)?
>>
>
>> Sax or DOM...it depends on the usecase and the algorithmic approach 
>> you take. Sax is fast but you have to build your own datastructures, 
>> DOM is slow, takes a lot of memory but it gives you a tree to perform 
>> any fancy operation on it..
>
>
> DOM is also not particularly Pythonic (neither is SAX, but it is 
> relatively simple at least). You could also look into ElementTree (or 
> lxml, which implements that API too). ElementTree (though not yet 
> lxml) also introduces iterparse, which is a kind of streaming version 
> of the ElementTree API.
>
> ElementTree's API is a much nicer way to work with XML from Python 
> than DOM. Also it's more lightweight than even MiniDOM.
>
> Regards,
>
> Martijn


thanks for the info Martijn, I'm going to look at it.

I've done some work with ElementTree for CPSIO, and I haven't found it 
very easy to use because of all the extra namespace URI, and xpath stuff 
used for the tree navigation (xpath_findall, ..) which seem to get in 
the way. Also it could be that I find the DOM approach easier since I'm 
used to it in javascript already.

the question is also about being able to reuse parts of the 
export/import code of CMFSetup / GenericSetup and possibly simplify the 
zope2 -> zope3 migration of existing applications.

best
/JM




More information about the Zope3-dev mailing list