Java XML Child Node Get getChildNodesByName(Element parent, String name)

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

Description

get Child Nodes By Name

License

Open Source License

Declaration

public static Node[] getChildNodesByName(Element parent, String name) 

Method Source Code


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

import java.util.ArrayList;
import java.util.List;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    public static Node[] getChildNodesByName(Element parent, String name) {
        List<Node> nodeList = new ArrayList<Node>();

        NodeList childNodes = parent.getChildNodes();
        int length = childNodes.getLength();
        for (int i = 0; i < length; i++) {
            Node current = childNodes.item(i);
            if (current.getNodeName().equals(name))
                nodeList.add(current);/*  w w  w .j ava2  s. c o m*/
        }

        Node[] nodes = new Node[nodeList.size()];
        nodeList.toArray(nodes);
        return nodes;
    }
}

Related

  1. getChildNodes(Node parent, String childName)
  2. getChildNodes(Node parentNode)
  3. getChildNodes(Node parentNode, String childName)
  4. getChildNodes(Node parentNode, String childNodeName)
  5. getChildNodes(Node rootNode, String childName)
  6. getChildNodesByName(Node element, String name, boolean caseSensitive)
  7. getChildNodesByName(Node element, String name, boolean caseSensitive)
  8. getChildNodesByName(Node element, String name, boolean caseSensitive)
  9. getChildNodesByName(Node node, String name)