lxml tostring quoting too much

Chris Down chris at chrisdown.name
Tue Aug 6 16:28:09 EDT 2013


On 2013-08-06 18:38, andrea crotti wrote:
> I would really like to do the following:
>
> from lxml import etree as ET
> from lxml.builder import E
>
> url = "http://something?x=10&y=20"
> l = E.link(url)
> ET.tostring(l) -> "<link>http://something?x=10&y=20</link>"
>
> However the lxml tostring always quotes the &, I can't find a way to
> tell it to avoid quoting it.

You're probably aware, but without the escaping, it is no longer well formed
XML. Why do you want to do that? Is there a larger underlying problem that
should be solved instead?

Either way, you can use "unescape" from the xml.sax.saxutils module[0].

Chris

0: http://docs.python.org/2/library/xml.sax.utils.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20130806/7535d70f/attachment.sig>


More information about the Python-list mailing list