Java XML NodeList getNodeValue(NodeList nodes, String tagName)

Here you can find the source of getNodeValue(NodeList nodes, String tagName)

Description

get Node Value

License

Apache License

Declaration

static String getNodeValue(NodeList nodes, String tagName) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    static String getNodeValue(NodeList nodes, String tagName) {
        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();
                }/*from  w ww .j  av  a 2 s  .c om*/
            }
        }
        return "";
    }
}

Related

  1. getNodes(String tagName, NodeList nodes)
  2. getNodesByName(String name, NodeList nodeList)
  3. getNodesOfType(NodeList list, short type)
  4. getNodeTrimValue(NodeList nodeList)
  5. getNodeValue(NodeList nodes)
  6. getNodeValue(String tagName, NodeList nodes)
  7. getOccurs(String nodeName, NodeList nodes)
  8. getTableIDOfTableAlias(String tableAlias, NodeList referList1, NodeList referList2)
  9. getText(NodeList elem)