Java XML Node Value getValue(Node node)

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

Description

get Value

License

Open Source License

Parameter

Parameter Description
node a parameter

Return

the value of any XML node, or the empty string "" if the node is null

Declaration

public static String getValue(Node node) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    /**/*  ww w  .j  a  v a2s. c o  m*/
     * 
     * @param node
     * @return the value of any XML node, or the empty string "" if the node is null
     */
    public static String getValue(Node node) {
        String val = "";
        if (node != null) {
            if (node instanceof Element) {
                val = node.getTextContent();
            } else if (node instanceof Attr) {
                val = ((Attr) node).getValue();
            } else {
                val = node.getNodeValue();
            }
        }
        return val;
    }
}

Related

  1. getNodeValueAsLong(Node node)
  2. getNodeValueAsTime(Node node)
  3. getValue(Node node)
  4. getValue(Node node)
  5. getValue(Node node)
  6. getValue(Node node, short nodeType)
  7. getValue(Node node, short nodeType)
  8. getValue(Node node, short nodeType)
  9. getValue(Node node, String Tag)