content = etree.iterparse(open(file_path, 'rb'), tag='my_tag')
while True:
try:
event, elem = content.next()
# process element
yield result
except (etree.XMLSyntaxError, StopIteration):
break
del content
The error raises at the end of the file therefore all elements are successfully processed.
Another workaround:
content = etree.iterparse (open(file_ path, 'rb'), tag='my_tag') XMLSyntaxError, StopIteration):
while True:
try:
event, elem = content.next()
# process element
yield result
except (etree.
break
del content
The error raises at the end of the file therefore all elements are successfully processed.