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

booleanisNotEmpty(NodeList nodeList)
Null-safe check if the specified nodeList is not empty.
return nodeList != null && nodeList.getLength() > 0;
booleanisNullOrEmpty(NodeList nodeList)
is Null Or Empty
return nodeList == null || nodeList.getLength() == 0;
Iterableiterable(final NodeList list)
iterable
if (list == null)
    return Collections.EMPTY_LIST;
return new Iterable<Node>() {
    int nextPos = 0;
    public Iterator<Node> iterator() {
        return new Iterator<Node>() {
            public Node next() {
                if (nextPos >= list.getLength())
...
Iterableiterable(NodeList nodeList)
iterable
return () -> new Iterator<Node>() {
    private int index = 0;
    @Override
    public boolean hasNext() {
        return index < nodeList.getLength();
    @Override
    public Node next() {
...
IterableiterableNodes(final NodeList nodeList)
Iterates over a NodeList.
return new Iterable<Node>() {
    @Override
    public Iterator<Node> iterator() {
        return new Iterator<Node>() {
            int index = 0;
            @Override
            public boolean hasNext() {
                return index < nodeList.getLength();
...
IterableiterableNodes(final NodeList nodeList)
iterable Nodes
return new AbstractList<Node>() {
    @Override
    public Node get(int index) {
        return nodeList.item(index);
    @Override
    public int size() {
        return nodeList.getLength();
...
ListlistOf(final NodeList nodeList)
list Of
return new AbstractList<Node>() {
    public Node get(int index) {
        return nodeList.item(index);
    public int size() {
        return nodeList.getLength();
};
...
ListlistOf(final NodeList nodeList)
list Of
return new AbstractList<Node>() {
    public Node get(int index) {
        return nodeList.item(index);
    public int size() {
        return nodeList.getLength();
};
...
MapmapNodeList(NodeList nodeList)
map Node List
Map<Node, Map> map = new LinkedHashMap<>();
for (int i = 0; i < nodeList.getLength(); i++) {
    Node node = nodeList.item(i);
    if (node.hasChildNodes()) {
        map.put(node, mapNodeList(node.getChildNodes()));
    } else {
        map.put(node, Collections.emptyMap());
return map;
StringmergeTextContent(final NodeList nodes)
merge Text Content
StringBuffer buf = new StringBuffer();
for (int i = 0; i < nodes.getLength(); i++) {
    Node n = nodes.item(i);
    final String text;
    switch (n.getNodeType()) {
    case Node.COMMENT_NODE:
    case Node.PROCESSING_INSTRUCTION_NODE:
        text = null;
...