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

ListgetNodes(String tagName, NodeList nodes)
get Nodes
List<Node> nodeList = new ArrayList<Node>();
for (int x = 0; x < nodes.getLength(); x++) {
    Node node = nodes.item(x);
    if (node.getNodeName().equalsIgnoreCase(tagName)) {
        nodeList.add(node);
return nodeList;
...
ArrayListgetNodesByName(String name, NodeList nodeList)
Gets all nodes with a specific name
ArrayList<Node> nodes = new ArrayList<Node>();
for (int i = 0; i < nodeList.getLength(); i++) {
    if (nodeList.item(i).getNodeName().equals(name)) {
        nodes.add(nodeList.item(i));
return nodes;
ListgetNodesOfType(NodeList list, short type)
get Nodes Of Type
List<T> retVal = new ArrayList<T>(list.getLength());
for (int i = 0; i < list.getLength(); ++i) {
    Node n = list.item(i);
    if (n.getNodeType() == type) {
        retVal.add((T) n);
return retVal;
...
StringgetNodeTrimValue(NodeList nodeList)
Helper class to help parse the server response.
Element element = (Element) nodeList.item(0);
String nodeValue = "";
if (element != null) {
    NodeList itemNodeList = element.getChildNodes();
    int length = itemNodeList.getLength();
    for (int i = 0; i < length; i++) {
        Node node = ((Node) itemNodeList.item(i));
        if (node != null)
...
StringgetNodeValue(NodeList nodes)
get Node Value
Node node = nodes.item(0);
String value = null;
if (nodes.getLength() > 0) {
    NodeList children = node.getChildNodes();
    int length = children.getLength();
    if (length == 1) {
        Node textNode = children.item(0);
        value = textNode.getNodeValue();
...
StringgetNodeValue(NodeList nodes, String tagName)
get Node Value
for (int x = 0; x < nodes.getLength(); x++) {
    Node node = nodes.item(x);
    if (node.getNodeName().equalsIgnoreCase(tagName)) {
        NodeList childNodes = node.getChildNodes();
        for (int y = 0; y < childNodes.getLength(); y++) {
            Node data = childNodes.item(y);
            if (data.getNodeType() == Node.TEXT_NODE)
                return data.getNodeValue();
...
StringgetNodeValue(String tagName, NodeList nodes)
get Node Value
for (int x = 0; x < nodes.getLength(); x++) {
    Node node = nodes.item(x);
    if (node.getNodeName().equalsIgnoreCase(tagName)) {
        NodeList childNodes = node.getChildNodes();
        for (int y = 0; y < childNodes.getLength(); y++) {
            Node data = childNodes.item(y);
            if (data.getNodeType() == Node.TEXT_NODE) {
                return data.getNodeValue();
...
intgetOccurs(String nodeName, NodeList nodes)
Returns the occurrences of a given node (specified by its name) in a given list of nodes.
int occurs = 0;
int childNr = 0;
boolean foundFirstOccurence = false;
while (childNr < nodes.getLength()) {
    Node node = nodes.item(childNr);
    if (node.getNodeType() == Node.ELEMENT_NODE) {
        if (node.getNodeName().compareTo(nodeName) == 0) {
            occurs++;
...
StringgetTableIDOfTableAlias(String tableAlias, NodeList referList1, NodeList referList2)
get Table ID Of Table Alias
String tableID = tableAlias;
org.w3c.dom.Element workElement;
for (int j = 0; j < referList1.getLength(); j++) {
    workElement = (org.w3c.dom.Element) referList1.item(j);
    if (workElement.getAttribute("TableAlias").equals(tableAlias)
            || (workElement.getAttribute("ToTable").equals(tableAlias)
                    && workElement.getAttribute("TableAlias").equals(""))) {
        tableID = workElement.getAttribute("ToTable");
...
StringgetText(NodeList elem)
get Text
if (elem.getLength() > 0 && elem.item(0).getFirstChild() != null)
    return elem.item(0).getFirstChild().getTextContent();
return "";