Node.getTextContent() returns the text content of the current node and its descendants.
is there a way to get text content of the current node, not the descendant\'s tex
I do this with Java 8 streams and a helper class:
import java.util.*;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class NodeLists
{
/** converts a NodeList to java.util.List of Node */
static List list(NodeList nodeList)
{
List list = new ArrayList<>();
for(int i=0;i
And then
NodeLists.list(node)
.stream()
.filter(node->node.getNodeType()==Node.TEXT_NODE)
.map(Node::getTextContent)
.reduce("",(s,t)->s+t);