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

voidaddAll(final Node dst, final NodeList src)
Adds all Nodes of the source NodeList to the destination Node
final int size = size(src);
for (int i = 0; i < size; i++) {
    dst.appendChild(src.item(i));
ListasList(final NodeList scripts)
as List
return new AbstractList<Node>() {
    @Override
    public Node get(int index) {
        return scripts.item(index);
    @Override
    public int size() {
        return scripts.getLength();
...
ListasList(NodeList nodeList)
Returns a List view of the nodes in the given NodeList collection.
List<Node> nodes = new ArrayList<>();
for (int i = 0; i < nodeList.getLength(); i++) {
    nodes.add(nodeList.item(i));
return nodes;
ListcanonizeNodeList(NodeList nodelist)
Remove comments and whitespace-only text nodes
List<Node> list = new ArrayList<Node>(nodelist.getLength());
for (int i = 0; i < nodelist.getLength(); i++) {
    Node aItem = nodelist.item(i);
    if (aItem.getNodeType() == Node.COMMENT_NODE) {
        continue;
    } else if (aItem.getNodeType() == Node.TEXT_NODE) {
        if (aItem.getTextContent().matches("\\s*")) {
            continue;
...
NodeListcombine(final NodeList... nls)
Provides a NodeList of multiple nodelists
return new NodeList() {
    public Node item(final int index) {
        int offset = 0;
        for (int i = 0; i < nls.length; i++) {
            if (index - offset < nls[i].getLength()) {
                return nls[i].item(index - offset);
            } else {
                offset += nls[i].getLength();
...
Node[]combineNodeLists(NodeList successfulReportList, NodeList failedAssertList)
Combine two NodeList objects into an array of Node objects.
Node[] newList = new Node[successfulReportList.getLength() + failedAssertList.getLength()];
for (int i = 0; i < successfulReportList.getLength(); i++) {
    newList[i] = successfulReportList.item(i);
for (int i = 0; i < failedAssertList.getLength(); i++) {
    newList[i + successfulReportList.getLength()] = failedAssertList.item(i);
return newList;
...
booleancontainsElementByValue(NodeList elements, String value)
contains Element By Value
for (int i = 0; i < elements.getLength(); i++) {
    Node node = elements.item(i);
    if (node.getTextContent().equals(value)) {
        return true;
return false;
booleancontainsNature(NodeList nodes, String nature)
Check whether the given nature is represented by at least one node in nodes.
boolean contains = false;
for (int i = 0; !contains && i < nodes.getLength(); i++) {
    contains = checkNature(nodes.item(i), nature);
return contains;
SetconvertNodelistToSet(NodeList xpathNodeSet)
Method convertNodelistToSet
if (xpathNodeSet == null) {
    return new HashSet<Node>();
int length = xpathNodeSet.getLength();
Set<Node> set = new HashSet<Node>(length);
for (int i = 0; i < length; i++) {
    set.add(xpathNodeSet.item(i));
return set;
Node[]convertToArray(NodeList e)
convert To Array
int nodeSize = e.getLength();
Node[] output = new Node[nodeSize];
Node tempo = null;
for (int i = 0; i < nodeSize; i++) {
    tempo = e.item(i);
    output[i] = tempo;
return output;
...