[lxml-dev] ElementTree.write default_namespace argument
Hi there, I have lxml version 2.1.5, Python 2.5 both installed from Debian packages. I'd like to be able to use the default_namespace argument to ElementTree's write method. However, I get the following error: Traceback (most recent call last): File "./join-html-pages.py", line 62, in <module> main() File "./join-html-pages.py", line 59, in main document.write(file(new_filename, 'w'), encoding='utf-8', method='html', default_namespace='html') File "lxml.etree.pyx", line 1576, in lxml.etree._ElementTree.write (src/lxml/lxml.etree.c:16699) TypeError: write() got an unexpected keyword argument 'default_namespace' Is this expected behaviour? My application is extracting nodes from numerous XHTML documents and merging them into one HTML document. The bit that's going wrong is writing the resultant HTML to a file. I'm not really interested in it being correct XHTML or in using the correct namespace. So any alternative solutions would also be of interest. Cheers, Richard
Hi, Richard Lewis wrote:
I have lxml version 2.1.5, Python 2.5 both installed from Debian packages. I'd like to be able to use the default_namespace argument to ElementTree's write method.
Yep, that's not supported. It's not easy to add, and it would actually make more sense to change the prefix in the tree rather than on serialisation.
document.write(file(new_filename, 'w'), encoding='utf-8', method='html', default_namespace='html')
Note that 'html' is not a valid namespace URI.
My application is extracting nodes from numerous XHTML documents and merging them into one HTML document.
In which case there shouldn't be any namespace at all.
The bit that's going wrong is writing the resultant HTML to a file.
Could you elaborate on the "going wrong" bit? What is the result (of what kind of operation) and what did you expect instead? Note that lxml.html has an "xhtml_to_html()" function, maybe that helps already. Stefan
participants (2)
-
Richard Lewis
-
Stefan Behnel