Java tutorial
//package com.java2s; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { private Document document = null; public static Element getFirstChild(Document paramDocument, String paramString) { Element localElement = paramDocument.getDocumentElement(); return getFirstChild(localElement, paramString); } public static Element getFirstChild(Element paramElement, String paramString) { NodeList localNodeList = paramElement.getChildNodes(); for (int i = 0; i < localNodeList.getLength(); i++) { Node localNode = localNodeList.item(i); if ((localNode != null) && (localNode.getNodeType() == 1) && (((Element) localNode).getTagName().equals(paramString))) return (Element) localNode; } return null; } public static Element getFirstChild(Element paramElement, String paramString1, String paramString2, String paramString3) { NodeList localNodeList = paramElement.getChildNodes(); for (int i = 0; i < localNodeList.getLength(); i++) { Node localNode = localNodeList.item(i); if ((localNode != null) && (localNode.getNodeType() == 1) && (((Element) localNode).getTagName().equals(paramString1))) { Element localElement = (Element) localNode; if ((localElement.hasAttribute(paramString2)) && (paramString3.equals(localElement.getAttribute(paramString2)))) return localElement; } } return null; } public Element getFirstChild(String paramString) { return getFirstChild(this.document, paramString); } public Element getDocumentElement() { return this.document.getDocumentElement(); } }