Java XML NodeList getNodeValue(String tagName, NodeList nodes)

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

Description

get Node Value

License

Apache License

Declaration

static public String getNodeValue(String tagName, NodeList nodes) 

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 public String getNodeValue(Node node) {
        NodeList childNodes = node.getChildNodes();
        for (int x = 0; x < childNodes.getLength(); x++) {
            Node data = childNodes.item(x);
            if (data.getNodeType() == Node.TEXT_NODE) {
                return data.getNodeValue();
            }/*from  w  ww.ja va 2 s .  co  m*/
        }
        return "";
    }

    static public String getNodeValue(String tagName, NodeList nodes) {
        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();
                    }
                }
            }
        }
        return "";
    }
}

Related

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