I have a bunch of XML files which are using prefixes but without the corresponding namespace declaration.
Stuff like:
<tal:block tal:condition="foo">
...
</tal:block>
or:
<div i18n:domain="my-app">
...
I know where those prefixes come from, an I tried the following, but without success:
from lxml import etree as ElementTree
ElementTree.register_namespace("i18n", "http://namespaces.zope.org")
ElementTree.register_namespace("tal", "http://xml.zope.org/namespaces/tal")
with open(path) as fp:
tree = ElementTree.parse(fp)
but lxml still chokes with:
lxml.etree.XMLSyntaxError: Namespace prefix i18n for domain on div is not defined, line 4, column 20
I know I can use ElementTree.XMLParser(recover=True)
, but I would like to keep the prefix anyway, which this method don't.
Any idea?