Node.getTextContent() is there a way to get text content of the current node, not the descendant's text

后端 未结 4 764
眼角桃花
眼角桃花 2021-02-02 14:53

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

4条回答
  •  旧时难觅i
    2021-02-02 15:24

    If you change the last for loop into the following one it behaves as you wanted

    for (Node n = iterator.nextNode(); n != null; n = iterator.nextNode()) {           
        String tagname = ((Element) n).getTagName();
        StringBuilder content = new StringBuilder();
        NodeList children = n.getChildNodes();
        for(int i=0; i
                                                            
提交回复
热议问题