Node and NodeList are interfaces not class.
instanceof
was made for you.
This code :
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse( new File( "build.xml" ));
NodeList nodes = doc.getElementsByTagName( "target" );
System.err.println( nodes instanceof NodeList );
System.err.println( nodes.item( 0 ) instanceof Node );
System.err.println( nodes.item( 0 ) instanceof Element );
outputs:
true
true
true
You may write, after stack.pop()
, if( var instance of String )
or if( var instanceof Node )
... but IMHO it's not a good idea to mix different type into a single container.