xml.parsers.expat vs. xml.sax

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thomas Guettler

    xml.parsers.expat vs. xml.sax

    Hi!

    What are the difference between xml.parsers.exp at
    and xml.sax?

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

    I think xml.sax.make_pa rser uses expat as default.
    Why should I want to use xml.parsers.exp at?

    Regards,
    Thomas

  • Neil Benn

    #2
    Re: xml.parsers.exp at vs. xml.sax

    Hello,

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

    Basically xml.sax.XMLRead er 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:
    [color=blue]
    >Hi!
    >
    >What are the difference between xml.parsers.exp at
    >and xml.sax?
    >
    >Up to now I used xml.sax.make_pa rser and subclass
    >from ContentHandler.
    >
    >I think xml.sax.make_pa rser uses expat as default.
    >Why should I want to use xml.parsers.exp at?
    >
    > Regards,
    > Thomas
    >
    >
    >[/color]

    --

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

    Tel : +49 (351) 210 1300
    e-mail : benn@cenix-bioscience.com
    Cenix Website : http://www.cenix-bioscience.com


    Comment

    • Martijn Faassen

      #3
      Re: xml.parsers.exp at vs. xml.sax

      Thomas Guettler wrote:
      [color=blue]
      > What are the difference between xml.parsers.exp at
      > and xml.sax?
      >
      > Up to now I used xml.sax.make_pa rser and subclass
      > from ContentHandler.
      >
      > I think xml.sax.make_pa rser uses expat as default.
      > Why should I want to use xml.parsers.exp at?[/color]

      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

      Comment

      Working...