Java XML Child Get by Name getChildElements(Element parent, String localName)

Here you can find the source of getChildElements(Element parent, String localName)

Description

get Child Elements

License

LGPL

Declaration

public static List<Element> getChildElements(Element parent,
            String localName) 

Method Source Code

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

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 List<Element> getChildElements(Element parent,
            String localName) {/* ww w.  j a  v a 2  s.  c  o  m*/
        List<Element> elems = new ArrayList<Element>();
        NodeList nodes = parent.getChildNodes();
        for (int i = 0; i < nodes.getLength(); i++) {
            Node node = nodes.item(i);
            if (node.getNodeType() == Node.ELEMENT_NODE
                    && node.getLocalName().equals(localName)) {
                elems.add((Element) node);
            }
        }
        return elems;
    }
}

Related

  1. getChildElements(Element element, String namespace, String localName)
  2. getChildElements(Element element, String tag)
  3. getChildElements(Element element, String tagName)
  4. getChildElements(Element p_rootElement, String p_elementName)
  5. getChildElements(Element parent, String elementTag)
  6. getChildElements(Element parent, String name)
  7. getChildElements(Element parent, String name)
  8. getChildElements(Element parent, String name)
  9. getChildElements(Element parent, String nsUri, String localPart)