I am parsing an inappropriate XML file ( Sphinx xmlpipe2 format ) and would like the LXML parser to ignore the fact that there are unresolved namespace prefixes.
Sphinx XML Example:
<sphinx:schema> <sphinx:field name="subject"/> <sphinx:field name="content"/> <sphinx:attr name="published" type="timestamp"/> <sphinx:attr name="author_id" type="int" bits="16" default="1"/> </sphinx:schema>
I am aware of passing a keyword parameter to a parser to try to repair corrupted XML, for example.
parser = etree.XMLParser(recover=True) tree = etree.parse('sphinxTest.xml', parser)
but the above does not ignore the prefix, it removes it.
I could create a target that is added to the remote prefix, for example.
parser = etree.XMLParser(target = AddPrefix())
where AddPrefix() is a class that adds a prefix to each attribute tag. Is there an easier way to do this? In the end, I want to programmatically write the Sphinx xmlpipe2 format.
python xml lxml
chris
source share