Java XML First Child Element getFirstChild(Element parent, String name)

Here you can find the source of getFirstChild(Element parent, String name)

Description

get First Child

License

Open Source License

Declaration

public static Element getFirstChild(Element parent, String name) 

Method Source Code

//package com.java2s;
/******************************************************************************* 
 * Copyright (c) 2007-2012 Red Hat, Inc. 
 * Distributed under license by Red Hat, Inc. All rights reserved. 
 * This program is made available under the terms of the 
 * Eclipse Public License v1.0 which accompanies this distribution, 
 * and is available at http://www.eclipse.org/legal/epl-v10.html 
 * /*from   w w  w.j a  va2s  . co  m*/
 * Contributors: 
 *     Red Hat, Inc. - initial API and implementation 
 ******************************************************************************/

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    public static Element getFirstChild(Element parent, String name) {
        NodeList nl = parent.getChildNodes();
        for (int i = 0; i < nl.getLength(); i++) {
            Node n = nl.item(i);
            if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equals(name)) {
                return (Element) n;
            }
        }
        return null;
    }
}

Related

  1. getFirstChild(Element element, String child)
  2. getFirstChild(Element element, String namespaceUri, String localName)
  3. getFirstChild(Element element, String tag)
  4. getFirstChild(Element parent, String childTagName)
  5. getFirstChild(Element parent, String name)
  6. getFirstChild(Element root)
  7. getFirstChild(Element root, String name)
  8. getFirstChild(Element tag, String childTagName)
  9. getFirstChild(final Element el, final String name)