List of usage examples for org.w3c.dom Node getParentNode
public Node getParentNode();
From source file:Main.java
public static Node getParent(String tagName, Node node) { Node parent = node.getParentNode(); while (parent != null && !tagName.equalsIgnoreCase(parent.getNodeName())) { parent = parent.getParentNode(); }/* ww w .j a v a 2s .c o m*/ return parent; }
From source file:Main.java
public static void removeNode(Node node) { node.getParentNode().removeChild(node); }
From source file:Main.java
public static void removeElements(List<Node> listOfElements) { /* Method for removing all the elements in a list */ for (Node node : listOfElements) { node.getParentNode().removeChild(node); }/* w w w .j a v a 2s . c om*/ }
From source file:Main.java
public static Node getParentById(String id, Node node) { Node parent = node.getParentNode(); while (parent != null) { if (parent instanceof Element && id.equalsIgnoreCase(((Element) parent).getAttribute("id"))) { return parent; } else {/*from w w w . j ava 2s .c om*/ parent = parent.getParentNode(); } } return parent; }
From source file:Main.java
public static Node getRootParent(Node node) { Node root = node; while (root.getParentNode() != null) { root = root.getParentNode();// www. j a va 2s. c om } return root; }
From source file:Main.java
public static void insertBefore(Node source, Node target) { target.getParentNode().insertBefore(source, target); }
From source file:Main.java
/** * Removes all of the child nodes from a parent node. *///from w ww . j a va 2 s . co m public static void emptyNode(final Node parent) { final NodeList childNodes = parent.getChildNodes(); for (int i = childNodes.getLength() - 1; i >= 0; i--) { final Node childNode = childNodes.item(i); childNode.getParentNode().removeChild(childNode); } }
From source file:Main.java
/** * Removes all nodes of specified namespace * * @param dom w3c dom to be cleaned from spec. ns nodes * @param namespace // w w w . j av a 2 s . c o m */ public static void removeAllNodesOfNS(Document dom, String namespace) { List<Node> nodes = getAllNodesByNamespaceRecursive(dom, namespace); for (Node node : nodes) { node.getParentNode().removeChild(node); } }
From source file:Main.java
private static void removeEmptyTextNodes(final Document document) throws XPathExpressionException { final XPath xPath = XPathFactory.newInstance().newXPath(); final NodeList nodeList = (NodeList) xPath.evaluate("//text()[normalize-space()='']", document, XPathConstants.NODESET); for (int i = 0; i < nodeList.getLength(); ++i) { final Node node = nodeList.item(i); node.getParentNode().removeChild(node); }// ww w . j a va2 s. c o m }
From source file:Main.java
public static void removeNodes(Element parent, NodeList elements) { // Copy elements in case of NodeList is a live implementation // that would shrink while deleting elments List<Node> nodesToRemove = new ArrayList<Node>(); for (int i = 0; i < elements.getLength(); i++) { Node item = elements.item(i); if (item.getParentNode() == parent) { nodesToRemove.add(item);//from ww w . ja v a 2 s. c o m } } for (Node n : nodesToRemove) { parent.removeChild(n); } }