[Tutor] xml parsing from xml

Alan Gauld alan.gauld at btinternet.com
Wed May 7 19:39:25 CEST 2014


On 07/05/14 17:56, Stefan Behnel wrote:
> Alan Gauld, 07.05.2014 18:11:

>> and ElementTree (aka etree). The documenation gives examples of both. sax
>> is easiest and fastest for simple XML in big files ...
>
> I wouldn't say that SAX qualifies as "easiest". Sure, if the task is
> something like "count number of abc tags" or "find tag xyz and get an
> attribute value from it", then SAX is relatively easy and also quite fast.

That's pretty much what I said. simple task, big file. sax is easy.

For anything else use etree.

> BTW, ElementTree also has a SAX-like parsing mode, but comes with a simpler
> interface and saner parser configuration defaults.

My experience was different. Etree is powerful but for simple
tasks I just found sax easier to grok. (And most of my XML parsing
is limited to simple extraction of a field or two.)


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list