Java tutorial
//package com.java2s; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathFactory; import org.w3c.dom.Document; import org.w3c.dom.NodeList; public class Main { public static NodeList getChildNodes(Document doc, String parentTag) { return getChildNodesByExpression(doc, "//" + parentTag + "/*"); } public static NodeList getChildNodesByExpression(Document doc, String expression) { try { XPath xpath = XPathFactory.newInstance().newXPath(); XPathExpression expr = xpath.compile(expression); Object result = expr.evaluate(doc, XPathConstants.NODESET); return (NodeList) result; } catch (Exception ex) { ex.printStackTrace(); } return null; } }