Java XML NodeList getNodeTrimValue(NodeList nodeList)

Here you can find the source of getNodeTrimValue(NodeList nodeList)

Description

Helper class to help parse the server response.

License

Open Source License

Parameter

Parameter Description
nodeList a parameter

Declaration

public static String getNodeTrimValue(NodeList nodeList) 

Method Source Code

//package com.java2s;
//By using the Tapjoy SDK in your software, you agree to the terms of the Tapjoy SDK License Agreement.

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

public class Main {
    /**/* ww w.  j  a  v  a  2s  . c om*/
     * Helper class to help parse the server response.
     * 
     * @param nodeList
     * @return
     */
    public static String getNodeTrimValue(NodeList nodeList) {
        Element element = (Element) nodeList.item(0);
        String nodeValue = "";

        if (element != null) {
            NodeList itemNodeList = element.getChildNodes();

            int length = itemNodeList.getLength();

            for (int i = 0; i < length; i++) {
                Node node = ((Node) itemNodeList.item(i));
                if (node != null)
                    nodeValue += node.getNodeValue();
            }

            if (nodeValue != null && !nodeValue.equals("")) {
                return nodeValue.trim();
            } else {
                return null;
            }
        }
        return null;
    }
}

Related

  1. getNodeListItems(NodeList nodeList)
  2. getNodeListLength(NodeList list)
  3. getNodes(String tagName, NodeList nodes)
  4. getNodesByName(String name, NodeList nodeList)
  5. getNodesOfType(NodeList list, short type)
  6. getNodeValue(NodeList nodes)
  7. getNodeValue(NodeList nodes, String tagName)
  8. getNodeValue(String tagName, NodeList nodes)
  9. getOccurs(String nodeName, NodeList nodes)