Java XML Node Value getNodeValue(Node node)

Here you can find the source of getNodeValue(Node node)

Description

Return the string value of the given node (eventually empty).

License

Open Source License

Parameter

Parameter Description
node a node

Return

the string value of the given node

Declaration

public static String getNodeValue(Node node) 

Method Source Code

//package com.java2s;

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

public class Main {
    /**/*  w  w  w.  j  a  v  a  2  s  .  c  o  m*/
     * Return the string value of the given node (eventually empty).
     * 
     * @param node
     *            a node
     * @return the string value of the given node
     */
    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 "";
    }
}

Related

  1. getNodeValue(Node node)
  2. getNodeValue(Node node)
  3. getNodeValue(Node node)
  4. getNodeValue(Node node)
  5. getNodeValue(Node node)
  6. getNodeValue(Node node)
  7. getNodeValue(Node node)
  8. getNodeValue(Node node)
  9. getNodeValue(Node node, String name, boolean trim)