Java XML Element Find getAllElements(Element config, String elementName)

Here you can find the source of getAllElements(Element config, String elementName)

Description

returns all the element with the given name

License

Open Source License

Declaration

public static List<Element> getAllElements(Element config,
        String elementName) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

import java.util.List;

import org.w3c.dom.Element;

import org.w3c.dom.NodeList;

public class Main {
    /**//  w w w.  j a  va2s.  com
     * returns all the element with the given name
     */
    public static List<Element> getAllElements(Element config,
            String elementName) {
        List<Element> out = new ArrayList<Element>();
        NodeList children = config.getChildNodes();
        for (int counter = 0; counter < children.getLength(); counter++) {
            if (children.item(counter) instanceof Element) {
                Element el = (Element) children.item(counter);
                if (el.getTagName().equals(elementName)) {
                    out.add(el);
                }
            }
        }
        return out;
    }
}

Related

  1. findElement(final String idValue, final String idTagName, final String tagName, final Element root)
  2. findElementAsString(final Element e, final String find)
  3. findElementWithId(String id, Element root)
  4. findNodesByType(Element topElm, int type)
  5. findNodeValue(Element firstElement, String name)
  6. getAllElements(Element element)
  7. getAllElements(Node context)
  8. getAllElementsByTagName(Element elem, String name)
  9. getAllLeaveValues(Element element)