Java XML Node Value getNodeValue(Node node)

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

Description

Returns the value of given node

License

Open Source License

Parameter

Parameter Description
node node which value is to be returned

Return

the value of given node

Declaration

public static String getNodeValue(Node node) 

Method Source Code


//package com.java2s;
/*//www  .  j a v a2 s  .  c o m
* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). 
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:
*
*/

import org.w3c.dom.*;

public class Main {
    /**
     * Returns the value of given node
     * @param node node which value is to be returned
     * @return the value of given node
     */
    public static String getNodeValue(Node node) {
        String retval = "";
        try {
            Node firstChild = node.getFirstChild();
            if (firstChild != null)
                retval = firstChild.getNodeValue();
        } catch (Exception e) {
            return "";
        }
        return retval;
    }
}

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