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

MapgetEnvVariableMap(NodeList nodes)
get Env Variable Map
Map<String, String> map = new HashMap<String, String>();
for (int i = 0; i < nodes.getLength(); i++) {
    Node node = nodes.item(i);
    String name = node.getAttributes().getNamedItem("name").getTextContent();
    String value = node.getTextContent();
    map.put(name, value);
return map;
...
ElementgetFirst(NodeList nodes)
get First
if (nodes == null || nodes.getLength() == 0) {
    return null;
Node node = nodes.item(0);
if (node.getNodeType() != Node.ELEMENT_NODE) {
    return null;
return (Element) node;
...
ElementgetFirstElement(NodeList list)
get First Element
for (int i = 0; i < list.getLength(); i++) {
    if (list.item(i).getNodeType() == Node.ELEMENT_NODE)
        return (Element) list.item(i);
return null;
ElementgetFirstElement(NodeList list)
get First Element
return list.getLength() > 0 ? (Element) list.item(0) : null;
NodegetFirstElement(NodeList nodes)
Returns the first node in the node list that is an element.
for (int i = 0; i < nodes.getLength(); i++) {
    Node node = nodes.item(i);
    if (node.getNodeType() == Node.ELEMENT_NODE) {
        return node;
return null;
StringGetFirstInstance(NodeList nList)
Get First Instance
for (int i = 0; i < nList.getLength(); i++) {
    Node nNode = nList.item(i);
    if (nNode.getNodeType() == Node.ELEMENT_NODE) {
        Element eElement = (Element) nNode;
        if (eElement != null)
            return eElement.getTextContent();
return new String("");
NodegetFirstNode(NodeList nodeList)
get First Node
if (nodeList == null || nodeList.getLength() == 0)
    return null;
return nodeList.item(0);
StringgetFirstNodeValue(NodeList nodeList)
get First Node Value
String nodeValue = "";
StringBuffer varBuffer = new StringBuffer();
Node node = (Node) nodeList.item(0);
if (node != null) {
    NodeList childNodes = node.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        varBuffer.append(childNodes.item(i).getNodeValue().toString());
nodeValue = varBuffer.toString();
return nodeValue;
StringgetFirstTextValueFromNodeList(NodeList nList)
Gets the first text value of a NodeList
if (nList != null && nList.getLength() != 0) {
    return nList.item(0).getTextContent();
return null;
StringgetFirstValue(NodeList nodes)
get First Value
return (nodes.getLength() == 0 ? null : getValues(nodes).get(0));