Java XML Node Get by Name getElementsByTagName(Node node, String tagName)

Here you can find the source of getElementsByTagName(Node node, String tagName)

Description

get Elements By Tag Name

License

Apache License

Declaration

public static ArrayList<Element> getElementsByTagName(Node node, String tagName) 

Method Source Code

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

import java.util.ArrayList;

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

public class Main {
    public static ArrayList<Element> getElementsByTagName(Node node, String tagName) {
        ArrayList<Element> elements = new ArrayList<Element>();
        for (int i = 0; i < node.getChildNodes().getLength(); i++) {
            Node n = node.getChildNodes().item(i);
            if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equals(tagName)) {
                elements.add((Element) n);
            }/*from  w  ww  .  ja  v  a2 s .  com*/
        }
        return elements;
    }
}

Related

  1. getElementsByTagName(Node node, String tagname)
  2. getElementsByTagName(Node node, String tagName)
  3. getElementsByTagName(Node root, String tagName)
  4. getElementsByTagNameNS(Node element, String namespace, String name)
  5. getElementsByTagNames(Node node, String... tagName)