Java XML NodeList getNodeIntValue(String tagName, NodeList nodes)

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

Description

get Node Int Value

License

Apache License

Declaration

public static int getNodeIntValue(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 {
    public static int getNodeIntValue(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) {
                        try {
                            return Integer.parseInt(data.getNodeValue());
                        } catch (NumberFormatException e) {
                            return 0;
                        }/*from ww  w .j a v a  2  s. c  o  m*/
                    }
                }
            }
        }
        return 0;
    }

    public static 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();
            }
        }
        return "";
    }

    public static 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. getNode(String tagName, NodeList nodes)
  2. getNodeByNodeName(NodeList nodes, String nodeName)
  3. getNodeFromNodeList(NodeList list, String name)
  4. getNodeFromNodeList(NodeList nl, String nodeName, int index)
  5. getNodeFromNodeList(NodeList nodeList)
  6. getNodeList(Element from, String elementName)
  7. getNodeList(Node fatherNode, String nodeName)
  8. getNodeList(Node node, String tagName)
  9. getNodeList(Node pNode, String tagName)