For the problem of raising XMLSyntaxError on the next iteration right after the document root closes, the following workaround seems to step around the problem:
for (state, elem) in etree.iterparse(f): [...process...]
# Work around bug #1185701 by bailing out after the end of the document root.
if elem.getparent() is None:
break
For the problem of raising XMLSyntaxError on the next iteration right after the document root closes, the following workaround seems to step around the problem:
for (state, elem) in etree.iterparse(f):
[...process. ..]
# Work around bug #1185701 by bailing out after the end of the document root.
if elem.getparent() is None:
break