FW: [Jython-users] ERROR : parsing xml in jython

Discussion in 'Python' started by Divya Prakash, Dec 19, 2006.

  1. 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:]
    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)
    >
    Divya Prakash, Dec 19, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David McNab
    Replies:
    0
    Views:
    493
    David McNab
    Apr 9, 2004
  2. Pinegar, Kent T

    FW: [Jython-users] Jython Licensing Question

    Pinegar, Kent T, Jul 24, 2008, in forum: Python
    Replies:
    0
    Views:
    352
    Pinegar, Kent T
    Jul 24, 2008
  3. John Levine
    Replies:
    0
    Views:
    729
    John Levine
    Feb 2, 2012
  4. Erik Wasser
    Replies:
    5
    Views:
    450
    Peter J. Holzer
    Mar 5, 2006
  5. Steven D'Aprano
    Replies:
    0
    Views:
    127
    Steven D'Aprano
    Jan 17, 2013
Loading...

Share This Page