Here you can find the source of getChild(Element parent, String name)
Parameter | Description |
---|---|
parent | an Element |
name | name of child specified |
public static Element getChild(Element parent, String name)
//package com.java2s; /******************************************************************************* * Copyright (c) 2009, 2011 The University of Memphis. All rights reserved. * This program and the accompanying materials are made available * under the terms of the LIDA Software Framework Non-Commercial License v1.0 * which accompanies this distribution, and is available at * http://ccrg.cs.memphis.edu/assets/papers/2010/LIDA-framework-non-commercial-v1.0.pdf *******************************************************************************/ import org.w3c.dom.Element; import org.w3c.dom.Node; public class Main { /**//from www.j av a2 s. com * Returns the first child of specified Element with specified name. * * @param parent * an {@link Element} * @param name * name of child specified * @return child or null */ public static Element getChild(Element parent, String name) { for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) { if (child instanceof Element && name.equals(child.getNodeName())) { return (Element) child; } } return null; } }