xpathEval fails for large files

Stefan Behnel stefan_ml at behnel.de
Wed Jul 23 02:05:47 EDT 2008


Kanch wrote:
> Original file was 18MB, and contained 288328 element attributes for
> the particular path.

You didn't say how many elements there are in total, but I wouldn't expect
that to be a problem, unless you have very little free memory (say, way below
256MB). I just tried with lxml 2.1 and a 40MB XML file with 300 000 elements
and it lets the whole Python interpreter take up some 140MB of memory in
total. Looping over all elements by calling "list(root.iter())" takes a bit
more than one second on my laptop. That suggests that /any/ solution involving
lxml (or cElementTree) will do just fine for you.


> I wonder whether for loop will cause a problem in iterating for 288328
> times.

You are heavily underestimating the power of the Python here.

Stefan



More information about the Python-list mailing list