By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,091 Members | 1,546 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,091 IT Pros & Developers. It's quick & easy.

xml.parsers.expat vs. xml.sax

P: n/a
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

Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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 : be**@cenix-bioscience.com
Cenix Website : http://www.cenix-bioscience.com
Jul 18 '05 #2

P: n/a
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
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.