When rendering XHTML using lxml, everything is fine, unless you are using Firefox, which seems to be unrelated to XHTML elements with pre-encrypted space and javascript. Although Opera can execute javascript (this is true for both jQuery and MathJax), regardless of whether the XHTML namespace has a prefix ( h: in my case) or not, in Firefox scripts will be interrupted with strange errors ( this.head undefined in case of MathJax).
I know about the register_namespace function, but does not accept None and "" as a namespace prefix. I heard about _namespace_map in the lxml.etree module, but my Python complains that this attribute does not exist (version problem?)
Is there any other way to remove the namespace prefix for the XHTML namespace? Please note that str.replace , as suggested in the answer to another related question, is not a method that I could accept, since it does not know the XML semantics and can easily ruin the resulting document.
Upon request, you will find two examples ready to use. One with namespace prefixes and one without . The first one will display 0 in Firefox (wrong), and the second will display 1 (correct). Opera will do both the right thing. This is obviously a Firefox bug , but it justifies the need for prefix XHTML with lxml - there are other good reasons to reduce traffic for mobile clients, etc. (even h: pretty much if you count dozens or hundret html tags).
source share