Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > elementtree -

Reply
Thread Tools

elementtree -

 
 
Jesper Olsen
Guest
Posts: n/a
 
      10-03-2004
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
 
Reply With Quote
 
 
 
 
Fredrik Lundh
Guest
Posts: n/a
 
      10-03-2004
Jesper Olsen wrote:

> 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>



 
Reply With Quote
 
 
 
 
Jesper Olsen
Guest
Posts: n/a
 
      10-04-2004
"Fredrik Lundh" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> Jesper Olsen wrote:
>
> > I'd like to output the element "<span>&nbsp;</span>"
> > and I try this
> >
> > w=XMLWriter(f)
> > w.element("span", "&nbsp;", id="txt")

>
> use chr(160).
>
> ("&nbsp;" isn't a standard XML entity, and the simple writer doesn't support
> custom entities.)
>
> </F>



Thanks, that worked.

/Jesper
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ElementTree.XML(string XML) and ElementTree.fromstring(string XML)not working Kee Nethery Python 12 06-27-2009 06:06 AM
effbot ElementTree question dayzman@hotmail.com Python 1 12-15-2004 07:29 AM
ElementTree and XPATH dayzman@hotmail.com Python 3 12-11-2004 02:54 PM
xml file structure for use with ElementTree? Stewart Midwinter Python 7 10-11-2004 05:41 AM
elementtree behavior Tim Arnold Python 2 09-27-2004 08:41 PM



Advertisments