xml.parsers.expat vs. xml.sax

T

Thomas Guettler

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
 
N

Neil Benn

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 said:
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 : (e-mail address removed)
Cenix Website : http://www.cenix-bioscience.com
 
M

Martijn Faassen

Thomas said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top