code: def subelement(element, xpath, tag, text, **kwargs):
      
      subelm = element.find(xpath)
  
      if subelm is None:
          subelm = etree.SubElement(element, tag)
      else:
          subelm.tag = tag
  
      subelm.text = text
      for attr, value in kwargs.items():
          subelm.set(attr, value)
  
      return subelm
docs: Searches element matching the *xpath* in *parent* and replaces it's *tag*,
      *text* and *kwargs* attributes.
  
      If the element in *xpath* is not found a new child element is created
      with *kwargs* attributes and added.
  
      Returns the found/created element.