in the anyway to get nodes value of a DOM's node while its not scripts? i mean because there could be tens of scripts codes in a page source , when we traversing the DOM tree of the corresponding page, And when we use the method node.getNodeValue() it will retrieve the content of node even if its scripts whic is none of my concern. i just would like to get the content of the node if its an actual text that appears in the page.
public void traverse( Node rootNode)
{
Stack stack = new Stack();
Node node=rootNode.getFirstChild();
while (node!=null) {
System.out.println(node.getNodeValue());
if ( node.hasChildNodes()) {
if (node.getNextSibling()!=null)
stack.push( node.getNextSibling() );
node = node.getFirstChild();
}
else {
node = node.getNextSibling();
if (node==null && !stack.isEmpty())
{
node=(Node) stack.pop();
}
}
i found out the answer by myself!