ElementTree -- adding one structure to another?

Jan Danielsson jan.m.danielsson at gmail.com
Wed Jun 27 07:50:08 CEST 2007

Jan Danielsson wrote:
>    If have an element tree representing an XML document, and I load
> another tree from a file, is there an easy way to stick the second tree
> into the first one?
>    fooElement = ET.SubElement(...)
>    tree = ET.parse(TEMPLDIR + '/welcome.xml')
>    elem = tree.getroot()
>    Now I want to stick elem as a subelement of fooElement. Do I need to
> traverse the elem tree manually, or is there a way to just 'stick it in
> there'?

   Found it two seconds after sending the post. fooElement.append().

Kind regards,
Jan Danielsson

More information about the Python-list mailing list