elementtree -

J

Jesper Olsen

Hi,

I'm using the XMLWriter from the effbot element tree module:
http://effbot.org/zone/xml-writer.htm

I'd like to output the element "<span>&nbsp;</span>"
and I try this

w=XMLWriter(f)
w.element("span", "&nbsp;", id="txt")

But that does not work because "&nbsp;" gets escaped to "&amp;nbsp;"
- and using " " does not work either because space does not get
escaped...
Is there a way to do this?

Another thing I noticed is when outputting the element

<meta http-equiv="content-type" content="text/html" />

then is not possible to generate this by passing attributes as
keywords
to the w.element method - so it is necessary to use the slightly less
elegant form

w.element("meta", None, {"http-equiv":"contenttype",
"content":"text/html"})

I guess there is no way to avoid this - since the module relies on
pythons
way of handling keyword parameters...

/Jesper
 
F

Fredrik Lundh

Jesper said:
I'd like to output the element "<span>&nbsp;</span>"
and I try this

w=XMLWriter(f)
w.element("span", "&nbsp;", id="txt")

But that does not work because "&nbsp;" gets escaped to "&amp;nbsp;"
- and using " " does not work either because space does not get
escaped...
Is there a way to do this?

use chr(160).

("&nbsp;" isn't a standard XML entity, and the simple writer doesn't support
custom entities.)

</F>
 
J

Jesper Olsen

Fredrik Lundh said:
use chr(160).

("&nbsp;" isn't a standard XML entity, and the simple writer doesn't support
custom entities.)

</F>


Thanks, that worked.

/Jesper
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top