Java XML First Child Element getDirectChildNodes(Node node, String name)

Here you can find the source of getDirectChildNodes(Node node, String name)

Description

get Direct Child Nodes

License

Open Source License

Declaration

public static List<Node> getDirectChildNodes(Node node, String name) 

Method Source Code


//package com.java2s;
import java.util.LinkedList;
import java.util.List;

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

public class Main {
    public static List<Node> getDirectChildNodes(Node node, String name) {
        LinkedList<Node> nodes = new LinkedList<Node>();

        NodeList childList = node.getChildNodes();
        for (int childIndex = 0; childIndex < childList.getLength(); childIndex++) {
            Node child = childList.item(childIndex);
            if (child.getNodeName().equals(name)) {
                nodes.add(child);// ww w.jav  a2  s. com
            }
        }

        return nodes;
    }
}

Related

  1. getDirectChildElementValue(Element p_rootElement, String p_elementName)
  2. getDirectChildElementValues(Element p_rootElement, String p_elementName)
  3. getDirectChildNamedElements( Element parent, String name)
  4. getDirectChildNode(Node node, String name)
  5. getDirectChildNodes(final Node parent, final String... nodeNames)
  6. getFirstChild(Element e)
  7. getFirstChild(Element e, String nsUri, String local)
  8. getFirstChild(Element elem, String childTag)
  9. getFirstChild(Element element)