p & br using ElementTree?
robert.kern at gmail.com
Wed Jun 27 06:48:38 CEST 2007
Jan Danielsson wrote:
> Hello all,
> 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?
Use the .tail attribute on the br element:
In : from xml.etree import ElementTree as ET
In : p = ET.Element('p')
In : p.text = 'Current date:'
In : br = ET.SubElement(p, 'br')
In : br.tail = '2000-01-01'
In : ET.dump(p)
<p>Current date:<br />2000-01-01</p>
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-list