Here you can find the source of getFirstChildElement(Node node, String tag)
public static Element getFirstChildElement(Node node, String tag)
//package com.java2s; /*/*from w w w . j a v a 2s . c o m*/ * Copyright 2017 The Portico Project * * This file is part of portico. * * portico is free software; you can redistribute it and/or modify * it under the terms of the Common Developer and Distribution License (CDDL) * as published by Sun Microsystems. For more information see the LICENSE file. * * Use of this software is strictly AT YOUR OWN RISK!!! * If something bad happens you do not have permission to come crying to me. * (that goes for your lawyer as well) * */ import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /** * Return the first child element under node that has given given tag name. * If there is none that matches, return null. */ public static Element getFirstChildElement(Node node, String tag) { NodeList list = node.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node temp = list.item(i); if (temp.getNodeType() != Node.ELEMENT_NODE) continue; Element tempElement = (Element) temp; if (tempElement.getTagName().equals(tag)) return tempElement; } return null; } }