Java XML Node Name getNode(Node node, String nodeName)

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

Description

get Node

License

Open Source License

Declaration

public static Node getNode(Node node, String nodeName) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

import java.util.List;

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

public class Main {
    public static Node getNode(Node node, String nodeName) {
        List<Node> childList = getChildNodesByName(node, nodeName);
        if (childList.size() > 0) {
            return childList.get(0);
        } else {//ww  w.ja  v  a  2  s. com
            return null;
        }
    }

    public static List<Node> getChildNodesByName(Node node, String name) {
        List<Node> result = new ArrayList<Node>();

        NodeList childList = node.getChildNodes();

        for (int i = 0; i < childList.getLength(); ++i) {
            Node child = childList.item(i);
            if (child.getNodeName().equals(name)) {
                result.add(child);
            }
        }

        return result;
    }
}

Related

  1. getName(Node node)
  2. getNode(final Node iNode, final String iNodeName)
  3. getNode(Node iNode, String iNodeName)
  4. getNode(Node iNode, String iNodeName)
  5. getNode(Node node, String nodeName)
  6. getNodeContent(Node item, String nodeName)
  7. getNodeContent(Node n, String nodename)
  8. getNodeName(Node node)
  9. getNodeName(Node node)