Java XML Element Get getElementsByTagName(Element node, String xmlns, String nodeName)

Here you can find the source of getElementsByTagName(Element node, String xmlns, String nodeName)

Description

Putting this in TestUtil and not XmlUtil since any production code could probably benefit by doing other work while iterating over NodeList directly, as opposed to looping once to construct this list we return, then iterating over it again to do such work.

License

Apache License

Declaration

public static List<Node> getElementsByTagName(Element node, String xmlns, String nodeName) 

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 {
    /**/*ww  w  .  ja  v a 2 s  .  c om*/
     * Putting this in TestUtil and not XmlUtil since any production code could probably benefit by doing other work while iterating over NodeList
     * directly, as opposed to looping once to construct this list we return, then iterating over it again to do such work.
     */
    public static List<Node> getElementsByTagName(Element node, String xmlns, String nodeName) {
        List<Node> nodes = new ArrayList<Node>();
        NodeList nodeList = node.getElementsByTagNameNS(xmlns, nodeName);
        for (int i = 0; i < nodeList.getLength(); i++) {
            nodes.add(nodeList.item(i));
        }
        return nodes;
    }
}

Related

  1. getElementsByTag(Element element, String tag)
  2. getElementsByTagName(Element aElement, String aTagName)
  3. getElementsByTagName(Element element, String tag)
  4. getElementsByTagName(Element element, String tagName)
  5. getElementsByTagName(Element node, String tagName)
  6. getElementsByTagNameNS1(Element element, String nsName, String tagName)
  7. getElementsByTagNameNS1(Element element, String nsName, String tagName)
  8. getElementsByXpath(Document docInput, String xPath)
  9. getElementsWithName(Document doc, String name)