Java XML Element Get by Name getElements(Element parent, String tagName)

Here you can find the source of getElements(Element parent, String tagName)

Description

get Elements

License

Apache License

Declaration

public static List<Element> getElements(Element parent, String tagName) 

Method Source Code

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

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> getElements(Element parent, String tagName) {
        NodeList nodes = parent.getElementsByTagName(tagName);
        List<Element> elements = new ArrayList();
        for (int i = 0; i < nodes.getLength(); i++) {
            Node node = nodes.item(i);
            if ((node instanceof Element)) {
                elements.add((Element) node);
            }/*from  w w w. j a  v a2  s .c om*/
        }
        return elements;
    }
}

Related

  1. getElementByTagNameWithParents(Element n, String... elementName)
  2. getElementDateValue(Document document, Element parent, String string)
  3. getElementFloatValue(Document document, Element parent, String element)
  4. getElements(Element parent, String localName)
  5. getElements(Element parent, String localname, String namespaceURI)
  6. getElements(Element parent, String tagName)
  7. getElements(Element parent, String tagName)
  8. getElements(Element parentElement, String nodeName)
  9. getElements(final Element parent, final String name)