code: protected Element updateElement(Counter counter, Element parent, String name, boolean shouldExist)
     {
        Element element = parent.getChild(name, parent.getNamespace());
        if ((element != null) && shouldExist)
        {
           counter.increaseCount();
        }
        if ((element == null) && shouldExist)
        {
           element = factory.element(name, parent.getNamespace());
           insertAtPreferredLocation(parent, element, counter);
           counter.increaseCount();
        }
        if (!shouldExist && (element != null))
        {
           int index = parent.indexOf(element);
           if (index > 0)
           {
              Content previous = parent.getContent(index - 1);
              if (previous instanceof Text)
              {
                 Text txt = (Text) previous;
                 if (txt.getTextTrim().length() == 0)
                 {
                    parent.removeContent(txt);
                 }
              }
           }
           parent.removeContent(element);
        }
        return element;
     }
docs: Method updateElement.
  
  @param counter
  @param shouldExist
  @param name
  @param parent