Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > jython lacks working xml processing modules?

Reply
Thread Tools

jython lacks working xml processing modules?

 
 
Jane Austine
Guest
Posts: n/a
 
      11-21-2003
I'm trying to parse an xml file with jython (not through java parsers
like xerces).

I tried minidom in jython 2.1 and 2.2a but all failed.

What can I do? The last resort would be using java parsers. Then how
can I use them like python xml parsers? It seems like javadom and
javasax has something to do, but I don't know how.

Jane
 
Reply With Quote
 
 
 
 
Andrew Clover
Guest
Posts: n/a
 
      11-21-2003
(Jane Austine) wrote:

> I'm trying to parse an xml file with jython (not through java parsers
> like xerces).


If all else fails, try pxdom. It's a pure-Python DOM/parser, so it should work
with Jython, but it's not going to be fast. At all.

http://www.doxdesk.com/software/py/pxdom.html

(BTW: new version coming this weekend, to catch up with the changes in the new
DOM 3 CRs.)

--
Andrew Clover
private.php?do=newpm&u=
http://www.doxdesk.com/
 
Reply With Quote
 
 
 
 
Alan Kennedy
Guest
Posts: n/a
 
      11-21-2003
[Jane Austine]
> I'm trying to parse an xml file with jython (not through java parsers
> like xerces).
>
> I tried minidom in jython 2.1 and 2.2a but all failed.


It's quite likely that your documents contained namespaces. The only
parser supported in jython is "xmlproc", because it is pure python.
However, "xmlproc" has some significant bugs in relation to namespace
processing, IIRC from the last time I looked at it.

> What can I do?


1. Use a Java SAX2 parser, write a jython ContentHandler for it, build
a Minidom from the events.
2. Use a Java DOM processor (DOM4J, JDOM, etc), and let it build a DOM
for you.

It would probably be easier if you could give an outline of what you
are trying to achieve. For example, do you really need to build an
object model? Do you need to use xpath? Do you need to validate
structures? Etc, etc.

> The last resort would be using java parsers. Then how
> can I use them like python xml parsers? It seems like javadom and
> javasax has something to do, but I don't know how.


If you want to know about using SAX events to build object models,
check this old thread on c.l.py.

http://groups.google.com/groups?hl=e...t%40python.org

If you have any specific questions or face any specific problems, post
some details.

regards,

--
alan kennedy
-----------------------------------------------------
check http headers here: http://xhaus.com/headers
email alan: http://xhaus.com/mailto/alan
 
Reply With Quote
 
Diez B. Roggisch
Guest
Posts: n/a
 
      11-21-2003
Jane Austine wrote:
> I'm trying to parse an xml file with jython (not through java parsers
> like xerces).
>
> I tried minidom in jython 2.1 and 2.2a but all failed.
>
> What can I do? The last resort would be using java parsers. Then how
> can I use them like python xml parsers? It seems like javadom and
> javasax has something to do, but I don't know how.


There is a really goog xml toolkit wich even covers xslt and some other
fancy stuff. Its called 4suite, and you can get it here:

http://www.4suite.org/

One of the authors, Uche Ogbuji, has some tutorials on working with it
on developerworks.

Diez

 
Reply With Quote
 
Jane Austine
Guest
Posts: n/a
 
      11-21-2003
Alan Kennedy <> wrote in message news:<>...
> [Jane Austine]
> > I'm trying to parse an xml file with jython (not through java parsers
> > like xerces).
> >
> > I tried minidom in jython 2.1 and 2.2a but all failed.

>
> It's quite likely that your documents contained namespaces.


No.

Jython 2.1 on java1.4.2-beta (JIT: null)
Type "copyright", "credits" or "license" for more information.
>>> from xml.dom import minidom
>>> minidom.parseString('<tag>foobar</tag>')

Traceback (innermost last):
File "<console>", line 1, in ?
File "C:\work\jython-2.1\Lib\xml\dom\minidom.py", line 913, in parseString
File "C:\work\jython-2.1\Lib\xml\dom\minidom.py", line 900, in _doparse
File "C:\work\jython-2.1\Lib\xml\dom\pulldom.py", line 251, in getEvent
AttributeError: feed
>>>



> The only
> parser supported in jython is "xmlproc", because it is pure python.


I can't make it work.

>>> import xml.sax,xml.dom.minidom
>>> p=xml.sax.make_parser(["xml.sax.drivers2.drv_xmlproc"])
>>> xml.dom.minidom.parseString('<tag>foobar</tag>',parser=p)

Traceback (innermost last):
File "<console>", line 1, in ?
File "C:\work\jython-2.1\Lib\xml\dom\minidom.py", line 913, in parseString
File "C:\work\jython-2.1\Lib\xml\dom\minidom.py", line 900, in _doparse
File "C:\work\jython-2.1\Lib\xml\dom\pulldom.py", line 251, in getEvent
AttributeError: feed

> However, "xmlproc" has some significant bugs in relation to namespace
> processing, IIRC from the last time I looked at it.
>
> > What can I do?

>
> 1. Use a Java SAX2 parser, write a jython ContentHandler for it, build
> a Minidom from the events.
> 2. Use a Java DOM processor (DOM4J, JDOM, etc), and let it build a DOM
> for you.
>
> It would probably be easier if you could give an outline of what you
> are trying to achieve. For example, do you really need to build an
> object model? Do you need to use xpath? Do you need to validate
> structures? Etc, etc.
>


I need the tree model of the xml document. So I'm trying to use DOM parsers.

> > The last resort would be using java parsers. Then how
> > can I use them like python xml parsers? It seems like javadom and
> > javasax has something to do, but I don't know how.

>
> If you want to know about using SAX events to build object models,
> check this old thread on c.l.py.
>
> http://groups.google.com/groups?hl=e...t%40python.org
>
> If you have any specific questions or face any specific problems, post
> some details.
>
> regards,

 
Reply With Quote
 
Alan Kennedy
Guest
Posts: n/a
 
      11-21-2003
[Alan Kennedy]
>> The only
>> parser supported in jython is "xmlproc", because it is pure python.


[Jane Austine]
> I can't make it work.
>
> >>> import xml.sax,xml.dom.minidom
> >>> p=xml.sax.make_parser(["xml.sax.drivers2.drv_xmlproc"])
> >>> xml.dom.minidom.parseString('<tag>foobar</tag>',parser=p)

> Traceback (innermost last):
> File "<console>", line 1, in ?
> File "C:\work\jython-2.1\Lib\xml\dom\minidom.py", line 913, in parseString
> File "C:\work\jython-2.1\Lib\xml\dom\minidom.py", line 900, in _doparse
> File "C:\work\jython-2.1\Lib\xml\dom\pulldom.py", line 251, in getEvent
> AttributeError: feed


Hmm, pity about that. To be honest, I'm not going to try and make it
work. Any time I need XML processing in jython, I use native Java xml
parsers, such as Xerces. I think most jython users work the same way.

[Alan Kennedy]
>> It would probably be easier if you could give an outline of what you
>> are trying to achieve. For example, do you really need to build an
>> object model? Do you need to use xpath? Do you need to validate
>> structures? Etc, etc.


[Jane Austine]
> I need the tree model of the xml document. So I'm trying to use DOM parsers.


I kind of figured that. My focus with the question was "Why do you
need a tree model"? Do you need to data extraction, structure
validation, xpath/xslt, etc?

If this helps, here is a jython snippet that creates a DOM using
Apache Xerces.

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

from java.io import StringReader

import org.xml.sax as sax
import org.apache.xerces.parsers.DOMParser as domparser

if __name__ == "__main__":
parser = domparser()
document = """<doc><a href="http://www.python.org"/></doc>"""
parser.reset()
documentIS = sax.InputSource(StringReader(document))
parser.parse(documentIS)
domtree = parser.getDocument()
results = domtree.getElementsByTagName('a')
for ix in range(results.getLength()):
print "Link found: uri=%s" % results.item(ix).getAttribute('href')

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

HTH,

--
alan kennedy
-----------------------------------------------------
check http headers here: http://xhaus.com/headers
email alan: http://xhaus.com/mailto/alan
 
Reply With Quote
 
Uche Ogbuji
Guest
Posts: n/a
 
      11-23-2003
"Diez B. Roggisch" <> wrote in message news:<bpksk3$1nt1ov$>...
> Jane Austine wrote:
> > I'm trying to parse an xml file with jython (not through java parsers
> > like xerces).
> >
> > I tried minidom in jython 2.1 and 2.2a but all failed.
> >
> > What can I do? The last resort would be using java parsers. Then how
> > can I use them like python xml parsers? It seems like javadom and
> > javasax has something to do, but I don't know how.

>
> There is a really goog xml toolkit wich even covers xslt and some other
> fancy stuff. Its called 4suite, and you can get it here:
>
> http://www.4suite.org/
>
> One of the authors, Uche Ogbuji, has some tutorials on working with it
> on developerworks.


Thanks for the plug, but 4Suite has a lot of C code in it and is
probably not an option for use in Java without some porting work.

--
Uche
http://uche.ogbuji.net
 
Reply With Quote
 
Paul Boddie
Guest
Posts: n/a
 
      11-24-2003
(Jane Austine) wrote in message news:< m>...
> I'm trying to parse an xml file with jython (not through java parsers
> like xerces).
>
> I tried minidom in jython 2.1 and 2.2a but all failed.
>
> What can I do? The last resort would be using java parsers. Then how
> can I use them like python xml parsers? It seems like javadom and
> javasax has something to do, but I don't know how.


The Java parsers seem to work quite well with the xml.dom.javadom
package. First, update your CLASSPATH with references to the necessary
..jar files - this can be a frustrating process, but I found that
xercesImpl-2.5.0.jar and xml-apis.jar were a good combination:

export CLASSPATH=.../xercesImpl-2.5.0.jar:.../xml-apis.jar

Then, start jython and try the following:

import xml.dom.javadom
impl = xml.dom.javadom.XercesDomImplementation()
# Use your own filename below!
doc = impl.buildDocumentFile("example.xml")
# Now, try some PyXML-style DOM properties and methods.
doc.childNodes
doc.childNodes[0].getAttribute("some-attr")

I'd seen javadom lurking in PyXML before now, but it's a nice surprise
to see that it works rather well, especially since I've never seen any
evidence of anyone using it (as far as I remember).

Paul
 
Reply With Quote
 
gaodexiaozheng@gmail.com
Guest
Posts: n/a
 
      07-17-2012
在 2003年11月24日星期一UTC+8下午7时42分31 ,Paul Boddie写道:
> (Jane Austine) wrote in message news:&lt; .com&gt;...
> &gt; I'm trying to parse an xml file with jython (not through java parsers
> &gt; like xerces).
> &gt;
> &gt; I tried minidom in jython 2.1 and 2.2a but all failed.
> &gt;
> &gt; What can I do? The last resort would be using java parsers. Then how
> &gt; can I use them like python xml parsers? It seems like javadom and
> &gt; javasax has something to do, but I don't know how.
>
> The Java parsers seem to work quite well with the xml.dom.javadom
> package. First, update your CLASSPATH with references to the necessary
> .jar files - this can be a frustrating process, but I found that
> xercesImpl-2.5.0.jar and xml-apis.jar were a good combination:
>
> export CLASSPATH=.../xercesImpl-2.5.0.jar:.../xml-apis.jar
>
> Then, start jython and try the following:
>
> import xml.dom.javadom
> impl = xml.dom.javadom.XercesDomImplementation()
> # Use your own filename below!
> doc = impl.buildDocumentFile(&quot;example.xml&quot
> # Now, try some PyXML-style DOM properties and methods.
> doc.childNodes
> doc.childNodes[0].getAttribute(&quot;some-attr&quot
>
> I'd seen javadom lurking in PyXML before now, but it's a nice surprise
> to see that it works rather well, especially since I've never seen any
> evidence of anyone using it (as far as I remember).
>
> Paul


hi,do you know the PyXML whether can be supported by Jython ?
Looking forward to your reply!
Thanks
 
Reply With Quote
 
Stefan Behnel
Guest
Posts: n/a
 
      07-17-2012
, 17.07.2012 10:35:
> hi,do you know the PyXML whether can be supported by Jython ?


PyXML is a dead project, don't use it.

You can use ElementTree in Jython, just as in Python.

Stefan

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FW: [Jython-users] Jython Licensing Question Pinegar, Kent T Python 0 07-24-2008 01:38 PM
FW: [Jython-users] ERROR : parsing xml in jython Divya Prakash Python 0 12-19-2006 02:49 PM
VS 2005 "Web Deployment Projects" wdproj lacks macros? DBxGlock ASP .Net 6 11-18-2005 03:45 AM
Grrr.. Sipura SPA-2100 lacks "Sip-Proxy-Require" Mark UK VOIP 6 08-11-2005 07:56 AM
[Jython-users] ANN: SPIRO - a cPython->Jython bridge (amongst otheruses) David McNab Python 0 04-09-2004 10:20 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57