Message151336
I have extended the xml.etree.ElementTree.Element class and pass the text attribute in the arguments. This creates much more compact code:
import xml.etree.ElementTree as xml
class Element(xml.Element):
def __init__(self,tag,attrib={},**attrs):
super(xml.Element,self).__init__()
self.tag = tag
self.attrib = attrib
self.attrib.update(attrs)
self.text = self.attrib.pop('text',None)
self.tail = self.attrib.pop('tail',None)
self._children = []
if __name__ == '__main__':
from sys import stdout
test = Element('Hello',)
test2 = Element('World',{'humour':'excelent'},text = 'How do you do', tail="Fine")
test.append(test2)
xml.ElementTree(test).write(stdout,encoding="utf-8",xml_declaration="yes",method="xml") |
|
Date |
User |
Action |
Args |
2012-01-16 07:21:27 | paaguti | set | recipients:
+ paaguti |
2012-01-16 07:21:27 | paaguti | set | messageid: <1326698487.2.0.0622950382199.issue13796@psf.upfronthosting.co.za> |
2012-01-16 07:21:26 | paaguti | link | issue13796 messages |
2012-01-16 07:21:26 | paaguti | create | |
|