Here you can find the source of formatXML(Document document, org.w3c.dom.Element root, String tab)
Parameter | Description |
---|---|
document | a parameter |
root | a parameter |
tab | a parameter |
private static void formatXML(Document document, org.w3c.dom.Element root, String tab)
//package com.java2s; //License from project: Open Source License import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /**/* www .j a v a 2 s .c o m*/ * format XML into human readable form * @param document * @param root * @param tab */ private static void formatXML(Document document, org.w3c.dom.Element root, String tab) { NodeList children = root.getChildNodes(); // save the nodes in the array first Node[] nodes = new Node[children.getLength()]; for (int i = 0; i < children.getLength(); i++) nodes[i] = children.item(i); // insert identations for (int i = 0; i < nodes.length; i++) { root.insertBefore(document.createTextNode("\n" + tab), nodes[i]); if (nodes[i] instanceof org.w3c.dom.Element) formatXML(document, (org.w3c.dom.Element) nodes[i], " " + tab); } root.appendChild(document.createTextNode("\n" + tab.substring(0, tab.length() - 2))); } }