Java tutorial
//package com.java2s; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static void deleteNodes(Node node, String express) { NodeList dels = selectNodes(node, express); Node del; if (dels != null) { for (int i = 0; i < dels.getLength(); i++) { del = dels.item(i); if (del != null) del.getParentNode().removeChild(del); } } } public static NodeList selectNodes(Node node, String express) { NodeList result = null; XPathFactory xpathFactory = XPathFactory.newInstance(); XPath xpath = xpathFactory.newXPath(); try { result = (NodeList) xpath.evaluate(express, node, XPathConstants.NODESET); } catch (XPathExpressionException e) { e.printStackTrace(); } return result; } }