Java tutorial
//package com.java2s; import org.w3c.dom.Element; import org.w3c.dom.Node; public class Main { public static void moveDown(Node currentN) { Node nextSibling = findNextElement(currentN, false); Node nextNextSibling = findNextElement(nextSibling, false); Node parent = currentN.getParentNode(); parent.removeChild(currentN); if (nextNextSibling != null) { parent.insertBefore(currentN, nextNextSibling); } else parent.appendChild(currentN); } public static Element findNextElement(Node current, boolean sameName) { String name = null; if (sameName) { name = current.getNodeName(); } int type = Node.ELEMENT_NODE; return (Element) getNext(current, name, type); } public static Node getNext(Node current, boolean sameName) { String name = null; if (sameName) { name = current.getNodeName(); } int type = current.getNodeType(); return getNext(current, name, type); } public static Node getNext(Node current, String name, int type) { Node next = current.getNextSibling(); if (next == null) return null; for (Node node = next; node != null; node = node.getNextSibling()) { if (type >= 0 && node.getNodeType() != type) { continue; } else { if (name == null) { return node; } if (name.equals(node.getNodeName())) { return node; } } } return null; } }