To add a new child to an element c, use this method:
E
E.append (c)
You can use this method to add Comment and ProcessingInstruction
instances as children of an element, as well as Element instances.
Here is a conversational example:
>>> st = etree.Element ( "state", name="New Mexico" ) >>> etree.tostring(st) '<state name="New Mexico"/>' >>> co = etree.Element ( "county", name="Socorro" ) >>> st.append(co) >>> etree.tostring(st) '<state name="New Mexico"><county name="Socorro"/></state>' >>> rem = etree.Comment ( "Just another day in paradise." ) >>> st.append ( rem ) >>> etree.tostring(st) '<state name="New Mexico"><county name="Socorro"/><!-- Just another day in paradise. --></state>' >>>