Java tutorial
//package com.java2s; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; public class Main { public static synchronized void appendIndent(Element e, Node pos, int indent) { Document doc = e.getOwnerDocument(); if (indent == 0) { e.insertBefore(doc.createTextNode("\n"), pos); } for (int i = 0; i < indent; i++) { if (i == 0) { e.insertBefore(doc.createTextNode("\n\t"), pos); } else { e.insertBefore(doc.createTextNode("\t"), pos); } } } }