Code example for Stack

Methods: empty, peek, pop, push

0
		buffer.setLength(0);
	} 
	 
	public void characters(char[] ch, int start, int length) throws SAXException{
		//display all target value 
		if(stack.peek().equals(target) && isParent(parent)){
			buffer.append(new String(ch,start,length));
		} 
	} 
	 
	public void endElement(String uri,
						   String localName,
						   String qName) throws SAXException{
		if(stack.peek().equals(target) && buffer.length() != 0){
			System.out.println(buffer.toString().trim());
		} 
		stack.pop();
		buffer.setLength(0);
	} 
	 
	public void endDocument() throws SAXException{ 
		//System.out.println("Document end"); 
	} 
	 
	public boolean isParent(String item){
		if (parent.equals("all")) return true;
		else if(stack.empty()) return false;
		else{ 
			String tmp = stack.pop();
			boolean res = stack.peek().equals(item);
			stack.push(tmp);
			return res;
		} 
	} 
}