from lxml import etree as ET parser = ET.XMLParser(remove_blank_text=True) tree = ET.parse(file_xml,parser) root = tree.getroot() child1 = root.find('.//{http://www.isotc211.org/2005/gmd}child1') parent = child1.getparent() id = root.index(child1) child2 = ET.Element('{http://www.isotc211.org/2005/gmd}child2', nsmap = {'srv':'http://www.isotc211.org/2005/srv'}) child_child2 = ET.SubElement(child2,'{http://www.isotc211.org/2005/gco}CharacterString') child_child2.text = 'text' parent.insert(id+1,child2) ET.ElementTree(root).write(file_new_xml, pretty_print = True)