Java XML Child Get by Name getChildByName(Node node, String nodeName)

Here you can find the source of getChildByName(Node node, String nodeName)

Description

Find node by name.

License

CDDL license

Parameter

Parameter Description
node Node
nodeName String

Return

Node

Declaration

public static Node getChildByName(Node node, String nodeName) 

Method Source Code

//package com.java2s;
/*/*from   w w  w  .j av a2  s.  c  o  m*/
Copyright (c) 2013 eBay, Inc.
This program is licensed under the terms of the eBay Common Development and
Distribution License (CDDL) Version 1.0 (the "License") and any subsequent  version 
thereof released by eBay.  The then-current version of the License can be found 
at http://www.opensource.org/licenses/cddl1.php and in the eBaySDKLicense file that 
is under the eBay SDK ../docs directory.
*/

import org.w3c.dom.Node;

public class Main {
    /**
     * Find node by name.
     * @param node Node
     * @param nodeName String
     * @return Node
     */
    public static Node getChildByName(Node node, String nodeName) {
        org.w3c.dom.NodeList children = node.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            Node c = children.item(i);
            if (c.getNodeName().equals(nodeName))
                return c;
        }
        return null;
    }
}

Related

  1. getChildByName(final Element parent, final String name)
  2. getChildByName(final Element parent, final String name)
  3. getChildByName(Node node, String name)
  4. getChildByName(Node node, String name)
  5. getChildByName(Node node, String name)
  6. getChildByTagName(Element e, String name)
  7. getChildByTagName(Element element, String childElementName)
  8. getChildByTagName(Element element, String tag)
  9. getChildByTagName(Element element, String tagName)