code: @SuppressWarnings("unchecked")
     protected void replaceXpp3DOM(final Element parent, final Xpp3Dom parentDom, final Counter counter)
     {
        if (parentDom.getChildCount() > 0)
        {
           Xpp3Dom[] childs = parentDom.getChildren();
           Collection<Xpp3Dom> domChilds = new ArrayList<>();
           for (int i = 0; i < childs.length; i++)
           {
              domChilds.add(childs[i]);
           }
  
           ListIterator<Element> it = parent.getChildren().listIterator();
           while (it.hasNext())
           {
              Element elem = it.next();
              Iterator<Xpp3Dom> it2 = domChilds.iterator();
              Xpp3Dom corrDom = null;
              while (it2.hasNext())
              {
                 Xpp3Dom dm = it2.next();
                 if (dm.getName().equals(elem.getName()))
                 {
                    corrDom = dm;
                    break;
                 }
              }
              if (corrDom != null)
              {
                 domChilds.remove(corrDom);
                 replaceXpp3DOM(elem, corrDom, new Counter(counter.getDepth() + 1));
                 counter.increaseCount();
              }
              else
              {
                 it.remove();
              }
           }
  
           Iterator<Xpp3Dom> it2 = domChilds.iterator();
           while (it2.hasNext())
           {
              Xpp3Dom dm = it2.next();
              Element elem = factory.element(dm.getName(), parent.getNamespace());
              for (String attName : dm.getAttributeNames())
              {
                 elem.setAttribute(attName, dm.getAttribute(attName));
              }
              insertAtPreferredLocation(parent, elem, counter);
              counter.increaseCount();
              replaceXpp3DOM(elem, dm, new Counter(counter.getDepth() + 1));
           }
        }
        else if (parentDom.getValue() != null)
        {
           parent.setText(parentDom.getValue());
        }
     }
docs: Method replaceXpp3DOM.
  
  @param parent
  @param counter
  @param parentDom