[lxml-dev] is tostring() confusing?

Ian Bicking ianb at colorstudy.com
Fri Jun 8 19:09:30 CEST 2007


Having tostring() as a function and not a method seems a bit odd to me. 
  I know it's from ElementTree, but at least for HTML it's awkward -- 
using lxml.etree.tostring on HTML is almost certain to create bad 
output; the output won't be real XHTML (lacking namespaces and it'll 
probably be invalid), and it will parse quite badly as HTML (<script 
src="..."/> for instance will typically break the entire page in a browser).

When I was first using ElementTree, I remember being a bit baffled by 
the lack of a serializing method.  I then found tostring and kind of 
forgot about it, but as I copy tostring methods around (e.g., 
lxml.html.tostring) it's starting to seem like a problem again.

-- 
Ian Bicking | ianb at colorstudy.com | http://blog.ianbicking.org
             | Write code, do good | http://topp.openplans.org/careers


More information about the lxml-dev mailing list