Java XML Child Node Get getChildNodesByName(Node element, String name, boolean caseSensitive)

Here you can find the source of getChildNodesByName(Node element, String name, boolean caseSensitive)

Description

Helper Method.

License

LGPL

Parameter

Parameter Description
element Element
name String
caseSensitive boolean

Return

ArrayList

Declaration

public static List<Node> getChildNodesByName(Node element, String name, boolean caseSensitive) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import org.w3c.dom.*;

import java.util.ArrayList;
import java.util.List;

public class Main {
    /**//from  w w  w  . ja  va  2s  . c  o m
     * Helper Method. Searches through the child nodes of an element and returns an array of the matching nodes.
     * @param element Element
     * @param name String
     * @param caseSensitive boolean
     * @return ArrayList
     */
    public static List<Node> getChildNodesByName(Node element, String name, boolean caseSensitive) {
        ArrayList<Node> nodes = new ArrayList<Node>();
        NodeList list = element.getChildNodes();
        for (int i = 0; i < list.getLength(); i++) {
            Node node = list.item(i);
            if (caseSensitive) {
                if (node.getNodeName().equals(name))
                    nodes.add(node);
            } else {
                if (node.getNodeName().equalsIgnoreCase(name))
                    nodes.add(node);
            }
        }
        return nodes;
    }
}

Related

  1. getChildNodes(Node parentNode, String childNodeName)
  2. getChildNodes(Node rootNode, String childName)
  3. getChildNodesByName(Element parent, String name)
  4. getChildNodesByName(Node element, String name, boolean caseSensitive)
  5. getChildNodesByName(Node element, String name, boolean caseSensitive)
  6. getChildNodesByName(Node node, String name)
  7. getChildNodesByTagName(final Element element, final String tagName)
  8. getChildNodesWithName(Node node, String name)
  9. getChildNodeText(Element element, String nodeTagName)