Java tutorial
//package com.java2s; import org.w3c.dom.Element; import org.w3c.dom.Node; public class Main { public static Element first(Element root, String localName) { if (root == null) return null; for (Node n1 = root.getFirstChild(); n1 != null; n1 = n1.getNextSibling()) { if (n1.getNodeType() != Node.ELEMENT_NODE) continue; return Element.class.cast(n1); } return null; } public static Element first(Element root, String namepaceUri, String localName) { if (root == null) return null; for (Node n1 = root.getFirstChild(); n1 != null; n1 = n1.getNextSibling()) { if (n1.getNodeType() != Node.ELEMENT_NODE) continue; Element e2 = Element.class.cast(n1); if (namepaceUri.equals(e2.getNamespaceURI()) && e2.getLocalName().equals(localName)) { return e2; } } return null; } }