I just sent you a pull request: https://github.com/lxml/lxml/pull/142
On 12/23/13 17:51, Stefan Behnel wrote:
Burak Arslan, 23.12.2013 12:40:
On 12/23/13 11:01, Stefan Behnel wrote:
Burak Arslan, 23.12.2013 09:56:
Is there a way to pass method='html' to etree.xmlfile()? Or any other way to serialize incrementally to html?
No, not currently. (Would be a new feature, maybe "htmlfile()".)
You could generate XHTML, though.
I'm not too interested in XHTML, but I could work on implementing support for a "method" argument to etree.xmlfile (or write a new html.htmlfile, whichever you deem more appropriate).
I'd prefer having an etree.htmlfile() class. The "xmlfile" class itself is fairly short anyway, it's purely an API class. The real work is done by the _IncrementalFileWriter. I suggest you add a "method" argument to the latter and pass it either OUTPUT_METHOD_XML or OUTPUT_METHOD_HTML from the two frontends.
Take care to disallow namespaces in HTML mode. Also, I'm not sure if there is anything to do about self-closing tags in HTML mode. I guess if people use the context manager to create them, they may just have to live with them being split into opening and closing tags ...
I also noticed that html.tostring doesn't suppress namespaces, but my patch does. Should I alter that behaviour?
I guess write_declaration() should raise an error in HTML mode.
The rest might even work more or less as it is. Most of the code you need to write might actually end up in tests.
It indeed seems to. Could you advise what kind of tests you think this code needs?
Best regards, Burak