jython lacks working xml processing modules?
Jane Austine
janeaustine50 at hotmail.com
Fri Nov 21 11:09:08 EST 2003
Alan Kennedy <alanmk at hotmail.com> wrote in message news:<3FBDF1E7.5ADB00B2 at hotmail.com>...
> [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=en&lr=&ie=UTF-8&selm=mailman.1058894673.16506.python-list%40python.org
>
> If you have any specific questions or face any specific problems, post
> some details.
>
> regards,
More information about the Python-list
mailing list