[Tutor] Extracting xml text

Karim karim.liateni at free.fr
Sun Jun 20 10:12:27 CEST 2010


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.



More information about the Tutor mailing list