Java tutorial
//package com.java2s; import java.util.List; import org.w3c.dom.Element; import org.w3c.dom.Node; public class Main { public static void getNamedChildrenWithWildcard(Element focus, String name, List<Element> children) { Element c = getFirstChild(focus); while (c != null) { String n = c.getLocalName() != null ? c.getLocalName() : c.getNodeName(); if (name.equals(n) || (name.endsWith("[x]") && n.startsWith(name.substring(0, name.length() - 3)))) children.add(c); c = getNextSibling(c); } } public static Element getFirstChild(Element e) { if (e == null) return null; Node n = e.getFirstChild(); while (n != null && n.getNodeType() != Node.ELEMENT_NODE) n = n.getNextSibling(); return (Element) n; } public static Element getNextSibling(Element e) { Node n = e.getNextSibling(); while (n != null && n.getNodeType() != Node.ELEMENT_NODE) n = n.getNextSibling(); return (Element) n; } }