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 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.
Did you actually re-implement bits of xmlNodeDumpOutput in xmlfile in a context-manager-friendly way?
Yes, necessarily. lxml actually replicates a fair bit of libxml2's functionality where the latter doesn't fit it's API well enough (or where lxml can do things more efficiently).
If so, should I start by looking at htmlNodeDumpFormatOutput from libxml?
No, _writeNodeToBuffer() handles this just fine when you pass the right method value.