Java XML Child Get by Name getChildElementsByName(Element parent, String elemName)

Here you can find the source of getChildElementsByName(Element parent, String elemName)

Description

get Child Elements By Name

License

LGPL

Declaration

public static List<Element> getChildElementsByName(Element parent, String elemName) 

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> getChildElementsByName(Element parent, String elemName) {
        List<Element> result = new ArrayList<Element>();
        NodeList nl = parent.getChildNodes();
        for (int i = 0; i < nl.getLength(); i++) {
            if (nl.item(i).getNodeType() == Node.ELEMENT_NODE) {
                Element elem = (Element) nl.item(i);
                if (elem.getNodeName().equals(elemName))
                    result.add(elem);//from  w  w  w.ja v  a 2s  .c o  m
            }
        }
        return result;
    }
}

Related

  1. getChildElements(Element parent, String tagName)
  2. getChildElements(Element parent, String tagName)
  3. getChildElements(Element parent, String tagName)
  4. getChildElements(Element parent, String tagName)
  5. getChildElementsByName(Element element, String localName)
  6. getChildElementsByName(Element parent, String name)
  7. getChildElementsByName(Element parent, String name)
  8. getChildElementsByName(Element parent, String tagName)
  9. getChildElementsByName(Element root, String tagName)