Efficiently counting elements in a very large XML doc using lxml

IRiNNaa

New Member
I have a very large (1.8GB) XML document. I'd like to simply find the number of elements with the tag \[code\]<Product>\[/code\].I've got this far: \[code\]context = etree.iterparse('./test.xml', tag='Product')num_elems = 0for event, elem in context: num_elems += 1print num_elems\[/code\]It works, but is there a faster way of doing it?
 
Back
Top