p & br using ElementTree?

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Jun 27 01:39:52 EDT 2007


En Wed, 27 Jun 2007 01:12:10 -0300, Jan Danielsson  
<jan.m.danielsson at gmail.com> escribió:

>    This is probably a mind numbingly brain dead question.. But how do I
> generate the following:
>
> <p>Current date:<br/>2000-01-01</p>
>
>    ..using ElementTree? The <p> element kind of needs two text blocks,
> as far as I can tell?

No, the date string goes into br's tail:

py> import xml.etree.ElementTree as ET
py> p=ET.fromstring
py> p=ET.fromstring("<p>Current date:<br/>2000-01-01</p>")
py> p
<Element p at b6a850>
py> p.text
'Current date:'
py> p.tail
py> p[0]
<Element br at b6aa58>
py> p[0].text
py> p[0].tail
'2000-01-01'

See <http://effbot.org/zone/element-infoset.htm> about infosets and the  
"mixed content" simplified model.

-- 
Gabriel Genellina



More information about the Python-list mailing list