Java XML Node Value getNodeValue(Node node)

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

Description

Gets the node value

License

Apache License

Parameter

Parameter Description
node Node

Return

String node value

Declaration

public static String getNodeValue(Node node) 

Method Source Code

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

import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class Main {
    /**// w  ww.java 2s.  c o  m
     * Gets a node's text value given its parent node and the name of the wanted child node.<br>
     * 
     * @param fatherNode the parent node
     * @param nodeName name of the wanted child node
     * @return String text node value
     */
    public static String getNodeValue(Node fatherNode, String nodeName) {
        String value = null;
        if (((Element) fatherNode).getElementsByTagName(nodeName) != null) {
            Node node = ((Element) fatherNode).getElementsByTagName(
                    nodeName).item(0);
            value = node.getTextContent();
            if (value != null) {
                value = value.trim();
            }
        }
        return value;
    }

    /**
     * Gets the node value
     * 
     * @param node Node 
     * @return String node value
     */
    public static String getNodeValue(Node node) {
        String value = null;
        if (node.getFirstChild() != null) {
            value = node.getFirstChild().getNodeValue();
        }
        return value;
    }
}

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)