jython lacks working xml processing modules?

Alan Kennedy alanmk at hotmail.com
Fri Nov 21 11:51:54 EST 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




More information about the Python-list mailing list