|
|
|
ElementTree, serialization and namespace prefixesThe way ElementTree
outputs namespaces in serialized output can be a problem with some
applications.
Here is an example of such an ouput : >>> import cElementTree as etree We can see that the declared namespaces are now given an alias and all prefixes are now changed using those defined aliases. This is absolutley correct in a XML point of view but you can be in trouble sometimes with some applications for which you are outputing XML from elementtree based Python programs because they do not support this properly on their side. Here is a workaround I found but I don't know if others exist : >>> import cElementTreeHere, this has been serialized without replacing the prefixes within qualifed names. The idea is that we are adding well known namespace prefixes to elementtree default ones. The default elementtre ones are defined within elementtree/ElementTree.py like below :
_namespace_map = {
This is not the best way I would have hope to find. Please let me know if you know any others. The problem I had recently was with OpenOffice.org 1.1.x. (I don't know about the version2 though).
I could parse and serialize OpenOffice.org content XML documents and
read them from OpenOffice.org at
first. But as soon as I was modifiying the document from OpenOffice.org then it wasn't taking
the namespace prefix aliases into consideration while inserting new
elements. I used this trick and now OpenOffice.org is happy. I'm gonna report
this issue to Laurent to
see if the OpenOffice.org
guys are aware about this issue. I fixed the issue as shown below. I used the nmspace.mod from the OOo dtd to find out the relevant OOo namespaces. OOo_NS = "http://openoffice.org/2000/" Important announcement: Join the Nuxeo team and contribute to the Nuxeo project! We have open positions in France and the UK for open source Java EE developers and sales engineers, both junior and senior. Trackback PingsTrackback URL for this entry:
http://blogs.nuxeo.com/sections/blogs/julien_anguenot/2006_02_23_elementtree-serialization-namespace-prefixes/tbping
Posted by Julien Anguenot @ 02/23/2006 03:56 PM.
-
Categories:
coding,
openoffice,
python
-
1 comments
|
Nuxeo Bloggers: Log in! Search Nuxeo Blogs
About this blog
Julien Anguenot ja [at] nuxeo [dot] com Nuxeo Bloggers
Photos and Pictures
|
|
Nuxeo -
Indesko -
Nuxeo 5 Project
All content is copyrighted by their author. CPSSkins is Copyright © 2003-2006 by Jean-Marc Orliaguet. | CPS is Copyright © 2002-2006 by Nuxeo SAS. |