Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #52066

Re: lxml tostring quoting too much

Date 2013-08-06 22:28 +0200
From Chris Down <chris@chrisdown.name>
Subject Re: lxml tostring quoting too much
References <CAF_E5JaWXk_JkXwx_fbdpV5zvU6Ys5f0+sNkkDj9A0u8M1Ea9A@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.272.1375823386.1251.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: lxml tostring quoting too much Chris Down <chris@chrisdown.name> - 2013-08-06 22:28 +0200

csiph-web