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

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

Description

get Elements By Tag Name

License

Open Source License

Declaration

public static List<Node> getElementsByTagName(Node root, String tagName) 

Method Source Code


//package com.java2s;
import java.util.ArrayList;

import java.util.List;

import org.w3c.dom.Node;

public class Main {

    public static List<Node> getElementsByTagName(Node root, String tagName) {

        List<Node> nodeList = new ArrayList<>();

        if (root != null && root.getChildNodes().getLength() > 0) {

            int childCount = root.getChildNodes().getLength();
            for (int i = 0; i < childCount; i++) {

                Node node = root.getChildNodes().item(i);

                if (tagName.equals(node.getNodeName())) {
                    nodeList.add(node);/*  ww w  .j  a v a  2 s .c om*/
                }
            }
        }

        return nodeList;
    }
}

Related

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