[Tutor] Extracting xml text

Karim karim.liateni at free.fr
Sun Jun 20 10:19:02 CEST 2010


In fact you must initialize the handler before parsing the xml doc and 
it should work.

Regards
Karim
France

On 06/20/2010 10:12 AM, Karim wrote:
>
> Hello,
>
> The following is an example which works for me to count opening tags 
> in a xml doc,
> if it can help:
>
> # -*- coding: iso-8859-1 -*-
> import sys
> from xml.parsers.expat import ParserCreate
>
> n = 0
> def start_element(name, attrs): # callback declaration
>     global n
>     n += 1
>
> parser = ParserCreate() # création du parser
> parser.StartElementHandler = start_element # initialization
> parser.ParseFile(file(sys.argv[1])) # get the input file
> print '%d opening tags' % n
>
> Regards
> Karim
> France
>
>
> On 06/20/2010 08:03 AM, T.R. D. wrote:
>> xml strings and so far it looks like the xml.parsers.expat is the way 
>> to go but I'm not quite sure how it works.
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list