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  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to