List of usage examples for org.w3c.dom Node insertBefore
public Node insertBefore(Node newChild, Node refChild) throws DOMException;
newChild
before the existing child node refChild
. From source file:Main.java
public static void replaceXPathNode(Node replaceThis, Node replaceWith) throws XPathExpressionException { Node parentNode = replaceThis.getParentNode(); parentNode.insertBefore(replaceWith, replaceThis); parentNode.removeChild(replaceThis); }
From source file:Main.java
public static void setFirst(Node parent, Node node) { Node first = parent.getFirstChild(); if (first != null) parent.insertBefore(node, first); else//from www . ja va2 s. c o m parent.appendChild(node); }
From source file:Main.java
private static void formatNode(Document doc, Node parent, Node node) { Node txt = doc.createTextNode("\n "); parent.insertBefore(txt, node); NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { txt = doc.createTextNode("\n "); node.insertBefore(txt, children.item(i)); i += 1;//from w ww. j a v a2 s .c o m } txt = doc.createTextNode("\n "); node.appendChild(txt); }
From source file:Main.java
public static void moveUp(Node currentN) { Node prevSibling = findPreviousElement(currentN, false); if (prevSibling != null) { Node parent = currentN.getParentNode(); parent.removeChild(currentN);/* w w w . ja v a2s. co m*/ parent.insertBefore(currentN, prevSibling); } }
From source file:Main.java
public static void moveUp(final Node currentN) { Node prevSibling = findPreviousElement(currentN, false); if (prevSibling != null) { Node parent = currentN.getParentNode(); parent.removeChild(currentN);// w ww. ja v a2 s .com parent.insertBefore(currentN, prevSibling); } }
From source file:Main.java
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);// w w w . j a v a 2 s. c om } else { parent.insertBefore(impNewNode, targetE.getNextSibling()); } return impNewNode; }
From source file:Main.java
public static void moveDown(Node currentN) { Node nextSibling = findNextElement(currentN, false); Node nextNextSibling = findNextElement(nextSibling, false); Node parent = currentN.getParentNode(); parent.removeChild(currentN);//from w w w. j av a 2s. c o m if (nextNextSibling != null) { parent.insertBefore(currentN, nextNextSibling); } else parent.appendChild(currentN); }
From source file:Main.java
public static void moveDown(final Node currentN) { Node nextSibling = findNextElement(currentN, false); Node nextNextSibling = findNextElement(nextSibling, false); Node parent = currentN.getParentNode(); parent.removeChild(currentN);/*www. java2 s . c o m*/ if (nextNextSibling != null) { parent.insertBefore(currentN, nextNextSibling); } else { parent.appendChild(currentN); } }
From source file:Main.java
public static void replaceNode(Document doc, Node parent, Node oldNode, Node newNode) { Node comment = doc.createComment(" Updated by FM GUI @ " + (new Date()) + " "); parent.insertBefore(comment, oldNode); parent.replaceChild(newNode, oldNode); formatNode(doc, parent, newNode);// ww w. ja v a2 s . c o m }
From source file:Main.java
public static void removeNode(Document doc, Node parent, Node node, String nodeName) { Node comment = doc.createComment(" '" + nodeName + "' was removed by FM GUI @ " + (new Date()) + " "); parent.insertBefore(comment, node); parent.removeChild(node);/*from ww w . j a v a2 s. co m*/ }