import java.io.*;
import java.util.*;

class Tokenizer2{

public static void main(String args[]) throws Exception{

Stack<String> stack = new Stack<String>();
BufferedReader br = new BufferedReader(new FileReader("test1.txt"));

StreamTokenizer parser = new StreamTokenizer( br );

// parser.wordChars( 0, 255 );
// parser.whitespaceChars( 9, 13 ); //tab, line feed, return
parser.ordinaryChar( '<' );
parser.ordinaryChar( '>' );
parser.ordinaryChar( '/' );
// parser.commentChar( '#' );

while ( parser.nextToken() != StreamTokenizer.TT_EOF )
{
if ( parser.ttype == StreamTokenizer.TT_WORD){
// System.out.println( "A word: " + stack.push(parser.sval) );
if(!stack.empty()&&stack.peek().equals(parser.sval )){
System.out.println( "pop off"+stack.pop());

}else{
System.out.println( "A word: " + stack.pus(parser.sval) );
}

}else {
System.out.println( "*: " + (char)parser.ttype);}
}
System.out.println(stack);

}
}

But with this code , I can not check mismatching tags or elements. E.g. <a></b> etc.
Can anyone help to provide kind suggestions?
Or any methods that can do the job?
Any of your suggestion will highly be appreciated.
Thanks a lot.