xml.parsers.expat vs. xml.sax

Discussion in 'Python' started by Thomas Guettler, Apr 27, 2004.

  1. Hi!

    What are the difference between xml.parsers.expat
    and xml.sax?

    Up to now I used xml.sax.make_parser and subclass
    from ContentHandler.

    I think xml.sax.make_parser uses expat as default.
    Why should I want to use xml.parsers.expat?

    Regards,
    Thomas
     
    Thomas Guettler, Apr 27, 2004
    #1
    1. Advertising

  2. Thomas Guettler

    Neil Benn Guest

    Hello,

    I'm fairly new to Python but I've had a fair bit of experience
    in SAX.

    Basically xml.sax.XMLReader is a simple implementation that doesn't
    do anything when you call parse, setFeature etc. Expat is an
    implementation of the XMLReader, therefore in actual fact you will never
    know that you are using Expat as an SAX XMLReader implmentation and you
    never should need to know - it is simply returned from make_parser The
    reason that SAX has this mechanism is that it easily allows you to
    switch implementations in and out. Take a look at the source code and
    it immediatly becaomes clear!

    This makes more sense in other languages which have formal
    interfaces but Python doesn't have such a thing (although you can
    acheive the same effect in other ways if you so desire).

    PS I'm new to Python so if that's wrong for the Python SAX
    implementation then please let me know!

    Cheers,

    Neil

    Thomas Guettler wrote:

    >Hi!
    >
    >What are the difference between xml.parsers.expat
    >and xml.sax?
    >
    >Up to now I used xml.sax.make_parser and subclass
    >from ContentHandler.
    >
    >I think xml.sax.make_parser uses expat as default.
    >Why should I want to use xml.parsers.expat?
    >
    > Regards,
    > Thomas
    >
    >
    >


    --

    Neil Benn
    Senior Automation Engineer
    Cenix BioScience
    PfotenhauerStrasse 108
    D-01307
    Dresden
    Germany

    Tel : +49 (351) 210 1300
    e-mail :
    Cenix Website : http://www.cenix-bioscience.com
     
    Neil Benn, Apr 27, 2004
    #2
    1. Advertising

  3. Thomas Guettler wrote:

    > What are the difference between xml.parsers.expat
    > and xml.sax?
    >
    > Up to now I used xml.sax.make_parser and subclass
    > from ContentHandler.
    >
    > I think xml.sax.make_parser uses expat as default.
    > Why should I want to use xml.parsers.expat?


    expat is slightly more low level. It *may* be more efficient but I
    wouldn't care about that.

    Using sax instead of expat is usually (always?) the right decision.
    There is more published API for sax, knowledge carries over from other
    languages, and sax has multiple implementations in Python.

    Regards,

    Martijn
     
    Martijn Faassen, Apr 27, 2004
    #3
    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. Will Stuyvesant

    Help with xml.parsers.expat please?

    Will Stuyvesant, Jul 4, 2003, in forum: Python
    Replies:
    1
    Views:
    709
    Alan Kennedy
    Jul 4, 2003
  2. Replies:
    2
    Views:
    810
    Kent Johnson
    May 4, 2005
  3. kaens
    Replies:
    6
    Views:
    348
    Stefan Behnel
    May 23, 2007
  4. kaens
    Replies:
    0
    Views:
    392
    kaens
    May 23, 2007
  5. sharan
    Replies:
    1
    Views:
    737
    Pavel Lepin
    Oct 26, 2007
Loading...

Share This Page