I use lxml and Python to write XML files. I was wondering what the accepted practice is: first create a document tree and then add auxiliary elements or add auxiliary elements and create a tree later? I know that this is unlikely to have any meaning in relation to the output, but I was interested to know what is the accepted norm in this from the point of view of coding.
Code example:
page = etree.Element('root')
doc = etree.ElementTree(page)
headElt = etree.SubElement(page, 'head')
Or that:
page = etree.Element('root')
headElt = etree.SubElement(page, 'head')
doc = etree.ElementTree(page)
source
share