Java XML Element Get by Name getElementsByTagName(Document doc, String tagName)

Here you can find the source of getElementsByTagName(Document doc, String tagName)

Description

get Elements By Tag Name

License

Open Source License

Declaration

public static Node[] getElementsByTagName(Document doc, String tagName) 

Method Source Code

//package com.java2s;

import org.w3c.dom.Document;

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

public class Main {
    public static Node[] getElementsByTagName(Document doc, String tagName) {
        try {// ww  w. j av a2  s  .  c o  m
            NodeList list = doc.getElementsByTagName(tagName);
            int length = list.getLength();
            if (length > 0) {
                Node[] array = new Node[length];
                for (int i = 0; i < length; i++) {
                    array[i] = list.item(i);
                }
                return array;
            }
            return null;
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }
}

Related

  1. getElements(Element parent, String tagName)
  2. getElements(Element parent, String tagName)
  3. getElements(Element parentElement, String nodeName)
  4. getElements(final Element parent, final String name)
  5. getElementsByName(Element parent, String name)
  6. getElementsByTagName(Element parent, String name, boolean localOnly)
  7. getElementsByTagName(Element parent, String tagName)
  8. getElementsByTagName(final Element parentElement, final String elementName)
  9. getElementsByTagNameCaseInsensitive( Document doc, final Set lowerCaseNames)