private void removeNodes(NodeList nl) { int count = nl.getLength(); for (int i = 0; i < count; i++) { Node node = nl.item(i); Node parent = node.getParentNode(); if (parent == null) continue; parent.removeChild(node); } }
private String getXPath(Node node, String xpath) { if (node == null) { return ""; } String nodeName = node.getNodeName(); Node parent = node.getParentNode(); if (parent == null) { return xpath; } return getXPath(parent, "/" + nodeName + xpath); }
private void replaceXmlEntry(Document doc, Node opReplace) { NodeList targetNodes = findNodes(doc, opReplace); NodeList valueNodes = getValueNodes(opReplace); if (targetNodes == null) { return; } int targetNodesCount = targetNodes.getLength(); for (int i = 0; i < targetNodesCount; i++) { Node target = targetNodes.item(i); Node parent = target.getParentNode(); if (parent == null) continue; parent.removeChild(target); appendNodes(doc, parent, valueNodes); } }