elementtree -

Discussion in 'Python' started by Jesper Olsen, Oct 3, 2004.

  1. Jesper Olsen

    Jesper Olsen Guest

    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
    Jesper Olsen, Oct 3, 2004
    #1
    1. Advertising

  2. 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>
    Fredrik Lundh, Oct 3, 2004
    #2
    1. Advertising

  3. Jesper Olsen

    Jesper Olsen Guest

    "Fredrik Lundh" <> wrote in message news:<>...
    > 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
    Jesper Olsen, Oct 4, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tim Arnold

    elementtree behavior

    Tim Arnold, Sep 27, 2004, in forum: Python
    Replies:
    2
    Views:
    248
    Fredrik Lundh
    Sep 27, 2004
  2. Stewart Midwinter

    xml file structure for use with ElementTree?

    Stewart Midwinter, Oct 9, 2004, in forum: Python
    Replies:
    7
    Views:
    361
    Stewart Midwinter
    Oct 11, 2004
  3. ElementTree and XPATH

    , Dec 9, 2004, in forum: Python
    Replies:
    3
    Views:
    344
    Martijn Faassen
    Dec 11, 2004
  4. Replies:
    1
    Views:
    302
    Fredrik Lundh
    Dec 15, 2004
  5. Kee Nethery
    Replies:
    12
    Views:
    2,044
    Stefan Behnel
    Jun 27, 2009
Loading...

Share This Page