Here you can find the source of getFirstChildElement(Element elm, String name)
public static Element getFirstChildElement(Element elm, String name)
//package com.java2s; /*//from w ww.j a v a 2s.c o m * Copyright 2004-2014 SmartBear Software * * Licensed under the EUPL, Version 1.1 or - as soon as they will be approved by the European Commission - subsequent * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * * http://ec.europa.eu/idabc/eupl * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the Licence for the specific language governing permissions and limitations * under the Licence. */ import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static Element getFirstChildElement(Element elm) { return getFirstChildElement(elm, null); } public static Element getFirstChildElement(Element elm, String name) { if (elm == null) { return null; } NodeList nl = elm.getChildNodes(); for (int c = 0; c < nl.getLength(); c++) { Node node = nl.item(c); if (node.getNodeType() == Node.ELEMENT_NODE && (name == null || node.getNodeName().equals(name))) { return (Element) node; } } return null; } }