FW: [Jython-users] ERROR : parsing xml in jython
Divya Prakash
Divyap at amdale.com
Tue Dec 19 09:49:21 EST 2006
Hi
But I am unable to parse all the nodes of the tree .....especially the
subtree of the main tree
It displays only the sibling not the subtree
Regards
Divya
-----Original Message-----
From: Matthias Berth [mailto:berth at decodon.com]
Sent: Tuesday, December 19, 2006 3:18 PM
To: Divya Prakash
Subject: Re: [Jython-users] ERROR : parsing xml in jython
Hi,
looks like you have to make an InputSource from the file, like so:
from java.io import File, FileReader, StringReader
textReader = FileReader(File(filename))
inputSource = InputSource(textReader)
dp.parse(inputSource)
Hope this helps
Matthias
Divya Prakash schrieb:
> Hi All,
>
>
>
> I m facing the problem while parsing xml file ..
>
>
>
> My code is :-
>
>
>
>
>
> import sys
>
> from org.apache.xerces.parsers import DOMParser as dp
>
> import javax.xml.parsers
>
> infilename = open("mos.xml","r")
>
> print infilename
> def test(infilename):
>
> """Parse XML document and show attributes and names.
>
> """
>
> print infilename
>
> parser = dp()
>
> print parser
>
> gh = parser.parse(infilename)
>
> print gh
>
> doc = parser.getDocument()
>
> node = doc.getFirstChild()
>
> print "Attributes:"
>
> show_attrs(node)
>
> print "Names:"
>
> show_names(node)
>
More information about the Python-list
mailing list