Java XML First Child Element getFirstNamedChildNode(Element element, String string)

Here you can find the source of getFirstNamedChildNode(Element element, String string)

Description

get First Named Child Node

License

Open Source License

Declaration

public static Node getFirstNamedChildNode(Element element, String string) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.//from   w  w w.  ja va 2 s.c  o  m
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 *
 * Contributors:
 *       Gregory Amerson - initial implementation and ongoing maintenance
 *******************************************************************************/

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

public class Main {
    public static Node getFirstNamedChildNode(Element element, String string) {
        NodeList children = element.getChildNodes();

        if (children != null && children.getLength() > 0) {
            for (int i = 0; i < children.getLength(); i++) {
                Node item = children.item(i);

                if (item.getNodeName().equals(string)) {
                    return item;
                }
            }
        }

        return null;
    }
}

Related

  1. getFirstLevelChildElementsByTagName(Element parent, String elementName)
  2. getFirstMatchedValueByChildTagName(Node parent, String name)
  3. getFirstMatchingDeepChildByTagName(final Element e, final String tagName)
  4. getFirstNamedChild(Node n, String name)
  5. getFirstNamedChild(Node node, String name)
  6. getFirstNamedChildNode(Node root, String nodeName)
  7. getFirstNontextChild(Node d)
  8. getFirstNonTextChild(Node root)
  9. getFirstTextChild(Node n)