code: def replace(self, child, *args, **kwargs):
          
  
          if 'set' in kwargs:
              set = kwargs['set']
              del kwargs['set']
          else:
              try:
                  set = child.set
              except AttributeError:
                  set = None
  
          if inspect.isclass(child):
              Class = child
              replace = Class.findreplaceables(self, set, **kwargs)
          elif (self.TEXTCONTAINER or self.PHONCONTAINER) and isstring(child):
              #replace will replace ALL text content, removing text markup along the way!
              self.data = []
              return self.append(child, *args,**kwargs)
          else:
              Class = child.__class__
              kwargs['instance'] = child
              replace = Class.findreplaceables(self,set,**kwargs)
              del kwargs['instance']
  
          kwargs['set'] = set #was deleted temporarily for findreplaceables
  
          if len(replace) == 0:
              #nothing to replace, simply call append
              if 'alternative' in kwargs:
                  del kwargs['alternative'] #has other meaning in append()
              return self.append(child, *args, **kwargs)
          elif len(replace) > 1:
              raise Exception("Unable to replace. Multiple candidates found, unable to choose.")
          elif len(replace) == 1:
              if 'alternative' in kwargs and kwargs['alternative']:
                  #old version becomes alternative
                  if replace[0] in self.data:
                      self.data.remove(replace[0])
                  alt = self.append(Alternative)
                  alt.append(replace[0])
                  del kwargs['alternative'] #has other meaning in append()
              else:
                  #remove old version competely
                  self.remove(replace[0])
              e = self.append(child, *args, **kwargs)
              self.updatetext()
              return e
docs: Appends a child element like ``append()``, but replaces any existing child element of the same type and set. If no such child element exists, this will act the same as append()
  
          Keyword arguments:
              alternative (bool): If set to True, the *replaced* element will be made into an alternative. Simply use :meth:`AbstractElement.append` if you want the added element
              to be an alternative.
  
          See :meth:`AbstractElement.append` for more information and all parameters.