protected Node popNode(Stack<Node> stack,Class<? extends Node> cls,String uri){
  Node top=stack.isEmpty() ? null : stack.peek();
  if (top != null) {
    if (nodeMatches(top,cls,uri)) {
      Node node=stack.pop();
      poppedNodes.push(node);
      return node;
    }
 else {
      for (int i=stack.size() - 2; i >= 0; i--) {
        if (nodeMatches(stack.get(i),cls,uri)) {
          Node node=stack.remove(i);
          poppedNodes.push(node);
          return node;
        }
      }
    }
  }
  return null;
}

protected Node popNode ( Stack < Node > stack , Class < ? extends Node > cls , String uri ) { Node top = stack . isEmpty ( ) ? null : stack . peek ( ) ; if ( top != null ) { if ( nodeMatches ( top , cls , uri ) ) { Node node = stack . pop ( ) ; poppedNodes . push ( node ) ; return node ; } else { for ( int i = stack . size ( ) - 2 ; i >= 0 ; i -- ) { if ( nodeMatches ( stack . get ( i ) , cls , uri ) ) { Node node = stack . remove ( i ) ; poppedNodes . push ( node ) ; return node ; } } } } return null ; }
this method pops a node of the defined class and optional uri from the stack . if the uri is not defined , then the latest node of the approach class will be chosen .
