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

Open Source License

Declaration

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

Method Source Code


//package com.java2s;

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

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static List<Element> getElements(Element parent, String tagName) {
        List<Element> elements = new ArrayList<Element>();
        NodeList nodes = parent.getElementsByTagName(tagName);
        for (int i = 0; i < nodes.getLength(); i++) {
            Node node = nodes.item(i);
            if (node instanceof Element) {
                elements.add(Element.class.cast(node));
            }//from   w ww .j a v  a2  s.c  om
        }
        return elements;
    }
}

Related

  1. getElementFloatValue(Document document, Element parent, String element)
  2. getElements(Element parent, String localName)
  3. getElements(Element parent, String localname, String namespaceURI)
  4. getElements(Element parent, String tagName)
  5. getElements(Element parent, String tagName)
  6. getElements(Element parentElement, String nodeName)
  7. getElements(final Element parent, final String name)
  8. getElementsByName(Element parent, String name)
  9. getElementsByTagName(Document doc, String tagName)