Java XML Node Text Value getStringValue(Node node)

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

Description

Return the String value of a Node.

License

BSD License

Parameter

Parameter Description
node a parameter

Declaration

private static String getStringValue(Node node) 

Method Source Code

//package com.java2s;
/**/*  w ww  . j  a va 2s.  co m*/
 * The contents of this file are subject to the license and copyright
 * detailed in the LICENSE and NOTICE files at the root of the source
 * tree and available online at
 *
 * http://www.dspace.org/license/
 */

import org.w3c.dom.Node;

public class Main {
    /**
     * Return the String value of a Node.
     * @param node
     * @return
     */
    private static String getStringValue(Node node) {
        String value = node.getNodeValue();

        if (node.hasChildNodes()) {
            Node first = node.getFirstChild();

            if (first.getNodeType() == Node.TEXT_NODE) {
                return first.getNodeValue();
            }
        }

        return value;
    }
}

Related

  1. getSingleNodeTextContent(Node node, String path)
  2. getStrElementValue(Node node)
  3. getString(final Node node, final String default_value)
  4. getString(Node node)
  5. getStringValue(NamedNodeMap values, String name)
  6. getStringValue(Node node)
  7. getTagValue(Node node, String name)
  8. getTagValueWithoutNamespace(Node n)
  9. getText(final Node node)