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

intgetCurrentListPosition(Node refNode, NodeList list)
returns an element's position in the given NodeList
if (refNode == null) {
    return -1;
int counter = 1;
for (int n = 0; n < list.getLength(); n++, counter++) {
    if (list.item(n) == refNode) {
        return counter;
return -1;
NodegetDeepNode(String name[], NodeList nodes)
get Deep Node
for (int i = 0; i < nodes.getLength(); i++) {
    Node node = nodes.item(i);
    if (node.getNodeName().equalsIgnoreCase(name[0])) {
        if (name.length == 1) {
            return node;
        } else {
            return getDeepNode(name, node.getChildNodes(), 1);
return null;
ArrayListgetDSNameListInScriptText(String scriptText, NodeList tableList)
get DS Name List In Script Text
ArrayList<String> fieldList = new ArrayList<String>();
int pos, posWrk, wrkInt, posWrk2;
String[] sectionDigit = { "(", ")", "{", "}", "+", "-", "/", "*", "=", "<", ">", ";", "|", "&", "\n", "\t",
        ",", " ", "!" };
String[] fieldProperty = { "value", "oldValue", "color", "enabled", "editable", "error", "valueChanged" };
boolean isFirstDigitOfField;
String variantExpression, wrkStr1, wrkStr2, dataSource;
org.w3c.dom.Element element;
...
ElementgetElementById(NodeList nodeList, String id)
Get Element that has attribute id="xyz".
Element element = null;
int len = nodeList.getLength();
for (int i = 0; i < len; i++) {
    Node node = (Node) nodeList.item(i);
    if (node.getNodeType() == Node.ELEMENT_NODE) {
        element = (Element) node;
        if (((Element) node).getAttribute("id").equals(id)) {
            break;
...
ElementgetElementFromItem(NodeList list, int index)
Get Element from Nodelist
return (Element) list.item(index);
ElementgetElementFromNodeList(NodeList nl)
Selects the (first) element from a node list and returns it.
if ((nl == null) || (nl.getLength() == 0)) {
    return null;
for (int i = 0; i < nl.getLength(); i++) {
    Node node = nl.item(i);
    if (node.getNodeType() == Node.ELEMENT_NODE) {
        return (Element) node;
return null;
ListgetElementList(NodeList list)
Filters all elements of a NodeList and returns them in a collection.
List<Element> col = new ArrayList<>(list.getLength());
for (int i = 0; i < list.getLength(); i++) {
    if (list.item(i) instanceof Element) {
        col.add((Element) list.item(i));
return col;
ListgetElements(NodeList nodeList, String localname, String namespaceURI)
Get the child elements having the supplied localname and namespace.
int count = nodeList.getLength();
Vector elements = new Vector();
for (int i = 0; i < count; i++) {
    Node node = nodeList.item(i);
    if (node.getNodeType() == Node.ELEMENT_NODE) {
        Element element = (Element) node;
        if (localname.equals("*") || getName(element).equals(localname)) {
            if (namespaceURI == null || namespaceURI.equals(element.getNamespaceURI())) {
...
ListgetElementsFromNodeList(final NodeList nodeList)
get Elements From Node List
final List<Element> elements = new ArrayList<>();
for (int i = 0; i < nodeList.getLength(); i++) {
    final Node node = nodeList.item(i);
    if (node instanceof Element) {
        elements.add((Element) node);
return elements;
...
Element[]getElementsOfNodeList(NodeList nodeList)
Returns an array containing the element objects in the provided node list.
Element[] ret = null;
@SuppressWarnings("rawtypes")
Vector v = new Vector();
for (int n = 0; n < nodeList.getLength(); n++) {
    Node item = nodeList.item(n);
    if (item.getNodeType() == Node.ELEMENT_NODE) {
        v.addElement(item);
ret = new Element[v.size()];
for (int n = 0; n < ret.length; n++) {
    ret[n] = (Element) v.elementAt(n);
return ret;