New submission from Pedro Andres Aranda Gutierrez <paag...@gmail.com>:
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") ---------- messages: 151336 nosy: paaguti priority: normal severity: normal status: open title: use 'text=...' to define the text attribute of and xml.etree.ElementTree.Element type: enhancement _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue13796> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com