|
From: Pekka L. <pek...@qe...> - 2005-08-11 13:01:03
|
Hello all,
I have simple Python code which can be used to create XML documents and
now I'd need to get that working with Jython. The features I need are
pretty basic -- creating an empty document, creating new elements,
adding child elements, setting attributes and outputting the generated
XML to a file. The code below shows all I need (the real code is of
course somewhat more complicated).
---------[code]-------------------------------
from xml.dom.minidom import Document
doc = Document()
root = doc.createElement("root")
root.setAttribute("attr", "value")
e1 = doc.createElement("e-1")
e1.setAttribute("a1", "v1")
e1.setAttribute("a2", "v2")
e2 = doc.createElement("e-2")
e21 = doc.createElement("e-2.1")
e21.setAttribute("a", "v")
e22 = doc.createElement("e-2.2")
doc.appendChild(root)
root.appendChild(e1)
root.appendChild(e2)
e2.appendChild(e21)
e2.appendChild(e22)
print doc.toprettyxml()
---------[output]-----------------------------
<?xml version="1.0" ?>
<root attr="value">
<e-1 a1="v1" a2="v2"/>
<e-2>
<e-2.1 a="v"/>
<e-2.2/>
</e-2>
</root>
---------[end]--------------------------------
I know that XML modules shipped with Jython 2.1 are a bit buggy and I
also noticed that Jython 2.2 alpha 1 doesn't contain any XML modules. In
general I'd like to move into 2.2 as soon as possible so I'm more
interested about solutions working with it. I've studied the problem a
bit and it seems that I have following two options with different pros
and cons.
1) Install Python XML modules to Jython.
+ Current code should work as is.
- Getting modules to work with Jython might require too much tweaking
(see e.g.
http://www.python.org/pycon/2005/papers/80/Server_side_jython%20V%201.2/Tweaking_PyXML_with_Jython.html).
The code must run on several machines and tweaking them all doesn't
sound too tempting.
2) Use Java XML libraries instead of Python ones
+ Should work in any machine where Jython is installed
- Need to write new (duplicate) code and maintain it
Can anyone here help making the decision? What have you done in similar
situation and did it work out?
Cheers,
.peke
PS: Thanks a lot for everyone involved with recent Jython development.
We've been using 2.2a1 without major problems (reported a non-fatal
regression with importing as a bug #1256506) and are waiting for
subsequent releases.
--
Qentinel Oy, Pekka Laukkanen
pek...@qe..., +358 40 7791909
Tekniikantie 14, 02150 Espoo, Finland
http://www.qentinel.com/
|