ElementTree oddities

Fredrik Lundh fredrik at pythonware.com
Mon Sep 15 11:33:12 EDT 2008


Brian Cole wrote:

> However, it's missing some of the text. For example, the following
> XML:
 >
>>>> xml = "<highlight><sp />Bar</highlight>"
> 
> Returns me a empty string. Seems the "<sp />" tag is borking it.
> 
> 
> Also, the for the following XML:
>>>> xml = "<highlight><ref>Bar</ref>:</highlight>"
> 
> I only get "Bar". It's missing the trailing colon.
> 
> I'm not that experienced with XML so perhaps I am just missing
> something here. Please enlighten me.

you're missing the "tail" attribute, which contains text that follows 
directly *after* the element's end tag.  it's not exactly a one-liner, 
but I usually use the one on this page:

    http://effbot.org/zone/element-bits-and-pieces.htm#gettext

</F>




More information about the Python-list mailing list