2014-11-21 109 views

回答

3

您可以使用tail屬性,我還沒有測試,但如你預期它應該工作:

e = ET.Element('p') 
# you set the text to hello first 
e.text = "hello " 
# and you set a subelement with br, which is what you want 
br = ET.SubElement(e, 'br') 
# then using tail to append the text after br 
br.tail = ' world' 

... 

希望這有助於。

+0

它的工作原理。謝謝。 – lionel319 2014-11-25 06:24:43