I'm parsing an xml document using iterparse.
from lxml import etree
import tempfile
content = """<root xmlns="blah.com">
<foo>
<attribute id="3" />
</foo>
<foo>
<structure>
<baz>
<x>g</x>
</baz>
</structure>
</foo>
</root>"""
src_file = tempfile.NamedTemporaryFile()
src_file.write(content)
src_file.flush()
context = etree.iterparse(
src_file.name,
events=("end", ),
tag="foo",
)
for event, element in context:
print event
print element
end
eventsA few things I tried:
xlmns:t="blah.com"
it also works fine.tag="foo"
also makes it work fine.However I would like to use both a base tag, and a default namespace. Is this a bug with iterparse? Am I doing something else wrong?
Edit: edited the code to make it copy-pasteable without ident errors.
Ah the problems with parsers! Your tag must also reflect the complete path. Use your namespace in the tag like so: tag="{blah.com}foo"
.