import java.io.ByteArrayInputStream;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Node;
import org.w3c.dom.bootstrap.DOMImplementationRegistry;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSSerializer;
public class XMLBeautifier {
Node document;
boolean keepDeclaration;
public XMLBeautifier(String xml) {
try {
this.document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(xml.getBytes())).getDocumentElement();
this.keepDeclaration = xml.startsWith("John SmithOla NordmannLanggt 234000 StavangerNorway- Empire BurlesqueSpecial Edition110.90
- Hide your heart19.90
";
System.out.println(new XMLBeautifier(xml).getXML());
}
}
------------------------ CONSOLE -------------------------
John Smith
Ola Nordmann
Langgt 23
4000 Stavanger
Norway
-
Empire Burlesque
Special Edition
1
10.90
-
Hide your heart
1
9.90