Java XML Node Value xmlNodeGetValue(Node node)

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

Description

Xml node get value.

License

Open Source License

Parameter

Parameter Description
node the node

Return

the string

Declaration

public static String xmlNodeGetValue(Node node) 

Method Source Code

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

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

public class Main {
    /**//from w w  w  . j  a va  2 s  .c o  m
     * Xml node get value.
     * 
     * @param node the node
     * 
     * @return the string
     */
    public static String xmlNodeGetValue(Node node) {
        NodeList list = node.getChildNodes();
        int len = list.getLength();
        if (len > 1)
            System.err.println("  Error: length of node=" + len + " for tag <" + node.getNodeName() + ">");
        for (int i = 0; i < len; i++) {
            Node n = list.item(i);
            // System.out.println ( " " + i + "> name=" + n.getNodeName() + ", value="
            // +
            // n.getNodeValue () + ", type=" + n.getNodeType() );
            if (n.getNodeType() == Node.TEXT_NODE) {
                return (n.getNodeValue());
            }
        }
        return (null); // not found
    }
}

Related

  1. setTextValue(Node node, String newValue)
  2. setTextValue(Node node, String value)
  3. setValueOfNode(Node node, String value)
  4. xmlGetFirstTextValue(Node node)
  5. xmlGetText(Node node)
  6. xmlToBean(Node beanNode)