Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > xml.parsers.expat vs. xml.sax

Reply
Thread Tools

xml.parsers.expat vs. xml.sax

 
 
Thomas Guettler
Guest
Posts: n/a
 
      04-27-2004
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

 
Reply With Quote
 
 
 
 
Neil Benn
Guest
Posts: n/a
 
      04-27-2004
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 : http://www.velocityreviews.com/forums/(E-Mail Removed)
Cenix Website : http://www.cenix-bioscience.com


 
Reply With Quote
 
 
 
 
Martijn Faassen
Guest
Posts: n/a
 
      04-27-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments