Java XML Element Get from Parent getNameToNodeList(Node parent, String node_name)

Here you can find the source of getNameToNodeList(Node parent, String node_name)

Description

get Name To Node List

License

LGPL

Declaration

public static Node[] getNameToNodeList(Node parent, String node_name) 

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 {
    public static Node[] getNameToNodeList(Node parent, String node_name) {
        List<Node> nodes = new ArrayList<>();
        if (parent == null || node_name == null)
            return nodes.toArray(new Node[0]);
        NodeList list = parent.getChildNodes();
        for (int i = 0; i < list.getLength(); i++) {
            Node node = list.item(i);
            if (node.getNodeName().equals(node_name)) {
                nodes.add(node);/*w  w  w.j a v a2s  .com*/
            }
        }
        return nodes.toArray(new Node[0]);
    }
}

Related

  1. getFirstNode(final Node parent, final String... path)
  2. getNamedElemValue(Element parent, String elementName)
  3. getNamedNodeList(Element parent, String containerTagName)
  4. getNamespacePrefix(Node parentNode, String preferredPrefix, String nsUri)
  5. getNameToFirstNode(Node parent, String node_name)
  6. getNodeAtPosition(Node parent, int offset)
  7. getNodeBean(Node parent)
  8. getNodeByLocalName(final Node parent, final String name)
  9. getNodeContents(Node parentNode)