From: cyberco <cy...@me...> - 2007-09-13 13:03:24
|
I would like to use the excellent ElementTree for some simple XML work, but unfortunately it depends on the shared lib 'expat' so Jython can't import it. Or can it? Anybody here that succeeded? I've read that previous versions of elementtree had a way to avoid expat by using SimpleXMLTreeBuilder, but that class has been removed now (although the error message still says "No module named expat; use SimpleXMLTreeBuilder instead"). If elementtree is a no go (I hope not) what other XML parsing package (python) or lib (java) would you recommend? (I prefer the Python packages since those are generally much simpler to use.) Cheers, Berco |
From: Moore, G. <Gre...@ad...> - 2007-09-13 19:22:56
|
Berco, I believe that if you can use a version of elementtree that doesn't have any C code in it you should be ok. The effbot website says "The Element type is available as a pure-Python implementation for Python 1.5.2 and later." Check out http://effbot.org/downloads/#elementtree. My understanding is that if its pure python and works with python 2.3 then it should work for Jython 2.2. If I've wrong, maybe one of the other list members will correct me. As far as other XML libs, I needed to use a Java class and 4domj http://www.dom4j.org/index.html seems, imho, to be one of the easier ones to use, provides a lot of features, and not too far off from the simplicity of elementtree.=20 Greg. -----Original Message----- From: jyt...@li... [mailto:jyt...@li...] On Behalf Of cyberco Sent: Thursday, September 13, 2007 6:03 AM To: jyt...@li... Subject: [Jython-users] XML in Jython: ElementTree? I would like to use the excellent ElementTree for some simple XML work, but unfortunately it depends on the shared lib 'expat' so Jython can't import it. Or can it? Anybody here that succeeded? I've read that previous versions of elementtree had a way to avoid expat by using SimpleXMLTreeBuilder, but that class has been removed now (although the error message still says "No module named expat; use SimpleXMLTreeBuilder instead"). If elementtree is a no go (I hope not) what other XML parsing package (python) or lib (java) would you recommend? (I prefer the Python packages since those are generally much simpler to use.) Cheers, Berco This message and any attachments are intended only for the use of the add= ressee and may contain information that is privileged and confidential. I= f the reader of the message is not the intended recipient or an authorize= d representative of the intended recipient, you are hereby notified that = any dissemination of this communication is strictly prohibited. If you ha= ve received this communication in error, please notify us immediately by = e-mail and delete the message and any attachments from your system. |
From: Jitendra N. <nai...@gm...> - 2007-09-14 03:56:56
|
The pure python does work , I am using the one available here http://effbot.org/downloads/elementtree-1.2.6-20050316.zip I unzipped and copied the "elementtree" subdirectory to jython/Lib directory and here is an interactive session . D:\jython2.2>jython Jython 2.2 on java1.5.0_12 Type "copyright", "credits" or "license" for more information. >>> from elementtree import ElementTree as ET >>> root = ET.Element("html") >>> head = ET.SubElement(root, "head") >>> title = ET.SubElement(head, "title") >>> title.text = "Page Title" >>> body = ET.SubElement(root, "body") >>> body.set("bgcolor", "#ffffff") >>> body.text = "Hello, World!" >>> tree = ET.ElementTree(root) >>> tree.write("page.xhtml") >>> import sys >>> tree.write(sys.stdout) <html><head><title>Page Title</title></head><body bgcolor="#ffffff">Hello, World !</body></html>>>> Regards Jitendra Nair On 9/13/07, cyberco <cy...@me...> wrote: > I would like to use the excellent ElementTree for some simple XML > work, but unfortunately it depends on the shared lib 'expat' so Jython > can't import it. Or can it? Anybody here that succeeded? > > I've read that previous versions of elementtree had a way to avoid > expat by using SimpleXMLTreeBuilder, but that class has been removed > now (although the error message still says "No module named expat; use > SimpleXMLTreeBuilder instead"). > > If elementtree is a no go (I hope not) what other XML parsing package > (python) or lib (java) would you recommend? (I prefer the Python > packages since those are generally much simpler to use.) > > Cheers, > Berco > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2005. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > |
From:
<Seb...@en...> - 2007-09-14 16:17:42
|
Jitendra Nair wrote: > The pure python does work ... out of the box, it works if you use methods that create XML documents from Elements, but not the other way round. > , I am using the one available here > http://effbot.org/downloads/elementtree-1.2.6-20050316.zip > > I unzipped and copied the "elementtree" subdirectory to jython/Lib directory > and here is an interactive session . > > D:\jython2.2>jython > Jython 2.2 on java1.5.0_12 > Type "copyright", "credits" or "license" for more information. > >>>> from elementtree import ElementTree as ET >>>> root = ET.Element("html") >>>> head = ET.SubElement(root, "head") >>>> title = ET.SubElement(head, "title") >>>> title.text = "Page Title" >>>> body = ET.SubElement(root, "body") >>>> body.set("bgcolor", "#ffffff") >>>> body.text = "Hello, World!" >>>> tree = ET.ElementTree(root) >>>> tree.write("page.xhtml") >>>> import sys >>>> tree.write(sys.stdout) >>>> > <html><head><title>Page Title</title></head><body bgcolor="#ffffff">Hello, World > !</body></html>>>> > > Regards > Jitendra Nair > > > > On 9/13/07, cyberco <cy...@me...> wrote: > >> I would like to use the excellent ElementTree for some simple XML >> work, but unfortunately it depends on the shared lib 'expat' so Jython >> can't import it. Or can it? Anybody here that succeeded? >> >> I've read that previous versions of elementtree had a way to avoid >> expat by using SimpleXMLTreeBuilder, but that class has been removed >> now (although the error message still says "No module named expat; use >> SimpleXMLTreeBuilder instead"). >> >> If elementtree is a no go (I hope not) what other XML parsing package >> (python) or lib (java) would you recommend? (I prefer the Python >> packages since those are generally much simpler to use.) >> >> Cheers, >> Berco >> >> ------------------------------------------------------------------------- >> This SF.net email is sponsored by: Microsoft >> Defy all challenges. Microsoft(R) Visual Studio 2005. >> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ >> _______________________________________________ >> Jython-users mailing list >> Jyt...@li... >> https://lists.sourceforge.net/lists/listinfo/jython-users >> >> > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2005. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > > |
From: Steve L. <lis...@ar...> - 2007-09-14 13:10:00
|
Hi, > The pure python does work , I am using the one available here > http://effbot.org/downloads/elementtree-1.2.6-20050316.zip Just out of curiosity, would it make sense to Java-ize the "real" ElementTree (or lxml) library by swapping out the lib's internal calls to c libraries w/ calls to java xml libraries while keeping the python interface to them the same? This way, scripts will be portable between Jython and CPython and still be relatively performant, no? If, as I'm assuming, using the all-python version in this case causes a severe(?) penalty hit. Thanks, -steve |
From: Pekka L. <pe...@ik...> - 2007-09-14 14:26:36
|
2007/9/14, Steve Lianoglou <lis...@ar...>: > Hi, > > > The pure python does work , I am using the one available here > > http://effbot.org/downloads/elementtree-1.2.6-20050316.zip > > Just out of curiosity, would it make sense to Java-ize the "real" > ElementTree (or lxml) library by swapping out the lib's internal > calls to c libraries w/ calls to java xml libraries while keeping the > python interface to them the same? In my opinion that makes a lot of sense. > This way, scripts will be portable between Jython and CPython and > still be relatively performant, no? If, as I'm assuming, using the > all-python version in this case causes a severe(?) penalty hit. Exactly. Having same API in Jython and CPython would be great but performance is often even more important. Cheers, .peke |
From: cyberco <cy...@me...> - 2007-09-16 10:24:18
|
As suggested by the author or ElementTree (Fredrik Lundh) I just copied 'SimpleXMLTreeBuilder' from a previous version. That worked when creating a tree from a string: ------------------------------- from elementtree import ElementTree, SimpleXMLTreeBuilder import StringIO memFile = StringIO.StringIO(someXmlString) tree = ElementTree.parse(memFile, SimpleXMLTreeBuilder.TreeBuilder()) ------------------------------- I think it would indeed be a good idea to swap out ElementTree's calls to C libs with calls to java libs, but: - Will it be really faster? (I must say that I get the feeling that the above code is pretty slow) - Only the treebuilder relies on 'expat' (the C lib), which can easily be circumvented by using ElementTree's own 'SimpleXMLTreeBuilder'. The reason Fredrik Lundh throws out the latter in the latest version is: "This module used *xmllib* to do the parsing, but since *expat* has been available from since around Python 2.0 or so, keeping the old support is pretty pointless." (See: http://effbot.org/zone/elementtree-13-intro.htm). Well, for jython it isn't really pointless. If 'SimpleXMLTreeBuilder' stays around Jython doesn't have to provide a custom ElementTree lib. Cheers, Berco On 9/14/07, Steve Lianoglou <lis...@ar...> wrote: > > Just out of curiosity, would it make sense to Java-ize the "real" > ElementTree (or lxml) library by swapping out the lib's internal > calls to c libraries w/ calls to java xml libraries while keeping the > python interface to them the same? > > This way, scripts will be portable between Jython and CPython and > still be relatively performant, no? If, as I'm assuming, using the > all-python version in this case causes a severe(?) penalty hit. > > Thanks, > -steve > |
From:
<Seb...@en...> - 2007-09-14 16:17:42
|
cyberco wrote: > I would like to use the excellent ElementTree for some simple XML > work, but unfortunately it depends on the shared lib 'expat' so Jython > can't import it. Or can it? Anybody here that succeeded? > > I've read that previous versions of elementtree had a way to avoid > expat by using SimpleXMLTreeBuilder, Even then, running SimpleXMLTreeBuilder with jython 2.2 yields: $ jython SimpleXMLTreeBuilder.py xmllib doesn't work properly in this Python version: - default namespace applied to unqualified attribute > but that class has been removed > now (although the error message still says "No module named expat; use > SimpleXMLTreeBuilder instead"). > > If elementtree is a no go (I hope not) what other XML parsing package > (python) or lib (java) would you recommend? (I prefer the Python > packages since those are generally much simpler to use.) > > Cheers, > Berco > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2005. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > > |
From: Charlie G. <cha...@gm...> - 2007-09-24 09:42:01
|
On 9/14/07, S=E9bastien Boisg=E9rault <Seb...@en...> wrot= e: > Even then, running SimpleXMLTreeBuilder with jython 2.2 yields: > > > $ jython SimpleXMLTreeBuilder.py > xmllib doesn't work properly in this Python version: > - default namespace applied to unqualified attribute This should be fixed in 2.2.1rc1. Give it a spin: http://downloads.sourceforge.net/jython/jython_installer-2.2.1rc1.jar Charlie |