Java tutorial
//package com.java2s; //License from project: Apache License import org.w3c.dom.Document; import org.w3c.dom.Node; public class Main { public static Node insertNewAfter(final Document impD, final Node targetE, final Node newE) { Node impNewNode = impD.importNode(newE, true); Node parent = targetE.getParentNode(); if (targetE.getNextSibling() == null) { parent.appendChild(impNewNode); } else { parent.insertBefore(impNewNode, targetE.getNextSibling()); } return impNewNode; } }