Java XML Node Value getNodeValue(Node node, String name, boolean trim)

Here you can find the source of getNodeValue(Node node, String name, boolean trim)

Description

get Node Value

License

Open Source License

Declaration

public static String getNodeValue(Node node, String name, boolean trim) 

Method Source Code

//package com.java2s;

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

public class Main {
    public static String getNodeValue(Node node, String name) {
        return getNodeValue(node, name, true);
    }/* w  w  w.  ja  va 2s .c  om*/

    public static String getNodeValue(Node node, String name, boolean trim) {
        String retValue = null;
        NodeList element = ((Element) node).getElementsByTagName(name);
        if (element.getLength() > 0) {
            NodeList valueNodeList = ((Element) element.item(0)).getChildNodes();

            if (valueNodeList.getLength() > 0) {
                retValue = valueNodeList.item(0).getNodeValue();
            }
        }

        return (trim && (retValue != null)) ? retValue.trim() : retValue;
    }
}

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, String name, String defaultVal, int index)
  7. getNodeValue(Node node, String nodeKey)
  8. getNodeValue(Node nodeXML)
  9. getNodeValue(org.w3c.dom.Node node)