Java XML Node Text Value getNodeText(Node node)

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

Description

get Node Text

License

Open Source License

Declaration

public static String getNodeText(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 {
    public static String getNodeText(Node node) {
        if (node == null) {
            return null;
        }//from  ww  w .ja v a 2 s.c o m

        String result = "";
        NodeList childList = node.getChildNodes();

        for (int i = 0; i < childList.getLength(); ++i) {
            Node child = childList.item(i);
            if (child.getNodeName().equals("#text")) {
                result = result + child.getNodeValue();
            } else {
                result = result + getNodeText(child);
            }
        }

        return result;
    }
}

Related

  1. getNamedItemText(NamedNodeMap map, String name)
  2. getNamespaceURIFromPrefix(Node context, String prefix)
  3. getNamespaceURIFromPrefix(Node context, String prefix)
  4. getNodeText(final Node node)
  5. getNodeText(Node node)
  6. getNodeText(Node node)
  7. getNodeText(Node node)
  8. getNodeText(Node node)
  9. getNodeText(Node node)