Issue with xml iterparse

Stefan Behnel stefan_ml at behnel.de
Sun Jun 13 08:13:15 EDT 2010


bfrederi, 03.06.2010 22:44:
> I am using lxml iterparse and running into a very obscure error. When
> I run iterparse on a file, it will occasionally return an element that
> has a element.text == None when the element clearly has text in it.

I assume you are referring to the 'start' event here, right? Tag content is 
not guaranteed to be parsed at this point, so containing text may or may 
not be available. Only the 'end' event guarantees that it has been parsed 
(well, or the 'start' event of a child element).


> I copy and pasted the problem xml into a python string, used StringIO
> to create a file-like object out of it

Note that the right thing to use in Py2.6 and later is "BytesIO".

Stefan




More information about the Python-list mailing list