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