Questions about parsing XML

Discussion in 'Python' started by Kyle Root, Aug 7, 2004.

  1. Kyle Root

    Kyle Root Guest

    I'm writing a practice program that parses an xml config file, at the
    moment I'm using expat. However I don't like some of it's behaviors.
    For example ParseFile() will parse the *entire* file and I don't want to
    do that. I would like to be able to tell it to find such and such a tag
    and return the cdata it contains, is this at all possible? If it is how
    would I handle optional tags?

    If it's not possible and the entire file does have to be parsed in one
    fell swoop, are there any special ways collecting the data into a usable
    form? I tried to put everything into a list, but that's not very
    practicle, especially with optional tags.

    Thanks,
    Kyle
     
    Kyle Root, Aug 7, 2004
    #1
    1. Advertising

  2. Kyle Root

    Jarek Zgoda Guest

    Kyle Root <> pisze:

    > I'm writing a practice program that parses an xml config file, at the
    > moment I'm using expat. However I don't like some of it's behaviors.
    > For example ParseFile() will parse the *entire* file and I don't want to
    > do that. I would like to be able to tell it to find such and such a tag
    > and return the cdata it contains, is this at all possible? If it is how
    > would I handle optional tags?


    libxml2 (http://www.xmlsoft.org/) has excellent support for XPath, F.
    Lundh's ElementTree also supports some XPath expressions, although it is
    built on expat and needs to parse whole XML document.

    --
    Jarek Zgoda
    http://jpa.berlios.de/
     
    Jarek Zgoda, Aug 7, 2004
    #2
    1. Advertising

  3. Kyle Root

    Kyle Root Guest

    Jarek Zgoda wrote:
    >
    >
    > libxml2 (http://www.xmlsoft.org/) has excellent support for XPath, F.
    > Lundh's ElementTree also supports some XPath expressions, although it is
    > built on expat and needs to parse whole XML document.
    >


    Well I was going to use that, but I remember reading somewhere that
    xmlib was depreciated or something, even if it has been do you still
    recommend libxml2 over expat?
     
    Kyle Root, Aug 7, 2004
    #3
  4. Kyle Root

    Jarek Zgoda Guest

    Kyle Root <> pisze:

    >> libxml2 (http://www.xmlsoft.org/) has excellent support for XPath, F.
    >> Lundh's ElementTree also supports some XPath expressions, although it is
    >> built on expat and needs to parse whole XML document.

    >
    > Well I was going to use that, but I remember reading somewhere that
    > xmlib was depreciated or something, even if it has been do you still
    > recommend libxml2 over expat?


    Python's xmllib (regular expression based parser) is not the same
    software as libxml2 (GNOME XML library) ;).

    If you need full support for XPath, XPointer, XInclude or namespaces
    (see http://www.xml.com/pub/a/2004/06/30/py-xml.html) I recommend using
    libxml2. Some people say that some of its parsers are also faster than
    original J. Clark's expat (although not as easy to use as expat or
    expat-like SAX parser from libxml2).

    --
    Jarek Zgoda
    http://jpa.berlios.de/
     
    Jarek Zgoda, Aug 7, 2004
    #4
  5. Kyle Root

    Kyle Root Guest

    Jarek Zgoda wrote:
    >
    > Python's xmllib (regular expression based parser) is not the same
    > software as libxml2 (GNOME XML library) ;).
    >
    > If you need full support for XPath, XPointer, XInclude or namespaces
    > (see http://www.xml.com/pub/a/2004/06/30/py-xml.html) I recommend using
    > libxml2. Some people say that some of its parsers are also faster than
    > original J. Clark's expat (although not as easy to use as expat or
    > expat-like SAX parser from libxml2).
    >


    Okay thank you very much!
    I like libxml2's docs better than the Python Library Reference anyways. :D
     
    Kyle Root, Aug 7, 2004
    #5
    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. Per Magnus L?vold
    Replies:
    0
    Views:
    1,388
    Per Magnus L?vold
    Nov 15, 2004
  2. Greg Wogan-Browne
    Replies:
    1
    Views:
    814
    Uche Ogbuji
    Jan 28, 2005
  3. Replies:
    2
    Views:
    503
  4. John Levine
    Replies:
    0
    Views:
    733
    John Levine
    Feb 2, 2012
  5. Erik Wasser
    Replies:
    5
    Views:
    465
    Peter J. Holzer
    Mar 5, 2006
Loading...

Share This Page