code: @SuppressWarnings("unchecked")
     protected Element findAndReplaceProperties(Counter counter, Element parent, String name, Map props)
     {
        boolean shouldExist = (props != null) && !props.isEmpty();
        Element element = updateElement(counter, parent, name, shouldExist);
        if (shouldExist)
        {
           Iterator it = props.keySet().iterator();
           Counter innerCounter = new Counter(counter.getDepth() + 1);
           while (it.hasNext())
           {
              String key = (String) it.next();
              findAndReplaceSimpleElement(innerCounter, element, key, (String) props.get(key), null);
           }
  
           List<String> lst = new ArrayList<String>(props.keySet());
           it = element.getChildren().iterator();
           while (it.hasNext())
           {
              Element elem = (Element) it.next();
              String key = elem.getName();
              if (!lst.contains(key))
              {
                 it.remove();
              }
           }
        }
        return element;
     }
docs: Method findAndReplaceProperties.
  
  @param counter
  @param props
  @param name
  @param parent