code: def add_element_to_doc(doc, tag, value):
      
      element = doc.find(".//%s" % tag)
      if element is None:
          element = etree.SubElement(doc, tag)
      element.text = value
docs: Set text value of an etree.Element of tag, appending a new element with given tag if it doesn't exist.