code: public void sortXml() {
          newDocument = (Document) originalDocument.clone();
          final Element rootElement = (Element) originalDocument.getRootElement().clone();
  
          HierarchyRootWrapper rootWrapper = factory.createFromRootElement(rootElement);
  
          rootWrapper.createWrappedStructure(factory);
          rootWrapper.detachStructure();
          rootWrapper.sortStructureAttributes();
          rootWrapper.sortStructureElements();
          rootWrapper.connectXmlStructure();
  
          newDocument.setRootElement(rootWrapper.getElementContent().getContent());
      }
docs: Creates a new dom document that contains the sorted xml.