Java Utililty Methods XML NodeList

List of utility methods to do XML NodeList

Description

The list of methods to do XML NodeList are organized into topic(s).

Method

NodeListgetNodeList(Node fatherNode, String nodeName)
Gets a node list from document, given the father node and the children node name.
NodeList list = null;
if (((Element) fatherNode).getElementsByTagName(nodeName) != null) {
    list = ((Element) fatherNode).getElementsByTagName(nodeName);
return list;
NodeListgetNodeList(Node node, String tagName)
get Node List
return getNodeList(NodeToElement(node), tagName);
NodeListgetNodeList(Node pNode, String tagName)
get Node List
Element nodeElement = (Element) pNode;
NodeList theNodeList = nodeElement.getElementsByTagName(tagName);
return theNodeList;
ArrayListgetNodeList(NodeList nl, String[] names, int pos)
Get the list of nodes matching the given array of tag names in the given node list
if ((nl == null) || (names.length - pos == 0))
    return null;
if (nl.getLength() == 0)
    return null;
ArrayList<Node> result = null;
if (names.length - pos == 1)
    result = new ArrayList<Node>();
for (int i = 0; i < nl.getLength(); i++) {
...
ListgetNodeList(NodeList nodeList)
get Node List
List<Node> results = new ArrayList<Node>();
int len = nodeList.getLength();
for (int i = 0; i < len; i++) {
    Node node = nodeList.item(i);
    if (node instanceof Element) {
        results.add(node);
    } else {
        continue;
...
ListgetNodeList(NodeList nodeList)
Method that returns only the Element objects of the specified NodeList
List<Element> nodes = new ArrayList<>();
for (int i = 0; i < nodeList.getLength(); i++) {
    Node node = nodeList.item(i);
    if (node instanceof Element)
        nodes.add((Element) node);
return nodes;
ListgetNodeListAsList(NodeList nl)
get Node List As List
ArrayList<Node> l = new ArrayList<Node>();
for (int i = 0; i < nl.getLength(); i++) {
    l.add(nl.item(i));
return l;
ListgetNodeListByName(Node node, String name, List finalNodeList)
get Node List By Name
NodeList nodeList = node.getChildNodes();
System.out.println("child node name: " + node.getNodeName());
if (nodeList == null)
    return null;
for (int i = 0; i < nodeList.getLength(); i++) {
    Node candNode = nodeList.item(i);
    if (candNode.getNodeName().equals(name)) {
        finalNodeList.add(candNode);
...
ListgetNodeListItems(NodeList nodeList)
get Node List Items
List<Node> nodes = Lists.newArrayList();
for (int i = 0; i < nodeList.getLength(); i++) {
    Node node = nodeList.item(i);
    if (node.getLocalName() != null) {
        nodes.add(node);
return nodes;
...
intgetNodeListLength(NodeList list)
get Node List Length
int length = 0;
try {
    length = list.getLength();
} catch (NullPointerException e) {
return length;