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

StringgetTextContent(NodeList nodeList)
get Text Content
Node node = getFirstNode(nodeList);
if (node == null)
    return null;
return node.getTextContent();
StringgetTextFields(NodeList list)
Extracts all text values from a list of Element nodes.
StringBuffer sb = new StringBuffer("");
for (int i = 0; i < list.getLength(); i++) {
    Node node = (Node) list.item(i);
    if (i > 0)
        sb.append("\n");
    sb.append(getTextValue(node));
return sb.toString();
...
StringgetXmlNodeValue(NodeList nodeList)
Extract the node string representation.
String retObj = null;
if (nodeList != null && nodeList.getLength() > 0) {
    Element element = (Element) nodeList.item(0);
    if (element != null && element.getChildNodes() != null) {
        NodeList childNodes = element.getChildNodes();
        if (childNodes != null && childNodes.getLength() > 0) {
            retObj = ((Node) childNodes.item(0)).getNodeValue();
return retObj;
booleanhasElementNodes(NodeList list)
Check whether there are any element nodes in a NodeList
final int length = list.getLength();
for (int i = 0; i < length; i++) {
    if (list.item(i).getNodeType() == Node.ELEMENT_NODE) {
        return true;
return false;
booleanhasImageNodes(NodeList nodeList)
has Image Nodes
for (int i = 0; i < nodeList.getLength(); i++) {
    Node n = nodeList.item(i);
    if (n != null) {
        if (n.getNodeType() == Node.ELEMENT_NODE) {
            Element element = ((Element) n);
            String tag = element.getTagName();
            if ("img".equals(tag) || "object".equals(tag)) {
                return true;
...
intindexOf(NodeList nodeList, String tagName, int startIdx)
index Of
for (int i = startIdx; i < nodeList.getLength(); i++) {
    Node node = nodeList.item(i);
    if (node.getNodeType() != Node.ELEMENT_NODE) {
        if (node.getNodeName().equals(tagName)) {
            return i;
return -1;
booleanisEmpty(@Nullable final NodeList aNL)
is Empty
return aNL == null ? true : aNL.getLength() == 0;
booleanisEmpty(NodeList nl)
Test if node list is null or empty.
return nl == null || nl.getLength() == 0;
booleanisListEmpty(NodeList list)
is List Empty
return list.getLength() == 0;
booleanisNodeListEmpty(final NodeList nodeList)
is Node List Empty
return nodeList == null || nodeList.getLength() == 0;