473,396 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

xml.parsers.expat vs. xml.sax

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
2 3893
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Will Stuyvesant | last post by:
There seems to be no XML parser that can do validation in the Python Standard Libraries. And I am stuck with Python 2.1.1. until my web master upgrades (I use Python for CGI). I know pyXML has...
0
by: dagurp | last post by:
I have this code: import xml.parsers.expat parser = xml.parsers.expat.ParserCreate(encoding="UTF-8") text = unicode("<div>þórður</div>",'UTF-8') print parser.Parse(text,1) And this is what I...
4
by: Laurens | last post by:
Hi, Is there any good open-source C++ XML parser library that isn't as huge as Xerces? The Xerces DLL is about 2.4 Mb in size, which is far too big for my application. (It doesn't seem to be...
2
by: Nikhil | last post by:
Hi, Does anybody knows faster parsers than C - RXP in validating category and Expat in non-validating category? Are both of them (or their faster ones) portable in Mac OS X? Thanks, ...
1
by: Avi Kak | last post by:
Hello: This questions relates to the behavior of the Perl SAX 2.0 parser XML::LibXML::SAX. (This behavior is also shown by the XML::SAX::Expat parser and, possibly by all other Perl SAX 2.0...
1
by: bloon | last post by:
I know there are three most popular open-source XML parsers. They are expat, libxml, and Xerces. All three are cross-platform. Does anybody test these three parsers? Which one is the fastest when...
2
by: dwelch91 | last post by:
Hi, c.l.p.'ers- I am having a problem with the import of xml.parsers.expat that has gotten me completely stumped. I have two programs, one a PyQt program and one a command line (text) program...
6
by: kaens | last post by:
Hey everyone, this may be a stupid question, but I noticed the following and as I'm pretty new to using xml and python, I was wondering if I could get an explanation. Let's say I write a simple...
1
by: josh logan | last post by:
Vincent Yau <y...@ohsu.eduwrites: Fast-forward to 2008 I installed Python 3.0b2 on a Windows Vista laptop (after having previously installed Python 2.5), and I am getting this same error: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.