public static boolean checkCommentNodes ( Node node , String str ) { // Get nodes of node and go through them NodeList children = node . getChildNodes ( ) ; for ( int i = 0 ; i < children . getLength ( ) ; i ++ ) { Node child = children . item ( i ) ; NodeList childChildren = child . getChildNodes ( ) ; if ( childChildren . getLength ( ) > 0 ) { // Recurse for all children boolean okDownThere = checkCommentNodes ( child , str ) ; if ( okDownThere == true ) { return true ; } } // Investigate comments if ( child . getNodeType ( ) == Node . COMMENT_NODE ) { // If we got a comment that contains the string we are happy Comment comment = ( Comment ) child ; if ( comment . getNodeValue ( ) . contains ( str ) ) { return true ; } } } return false ; }
Determines if there is a comment Node that contains the given string .