class MyHandle extends DefaultHandler {

	private ArrayList titleList;
	private boolean isTitle = false;
	private boolean isItem  = false;

	public void SetArr( ArrayList _titleList ) {
		titleList = _titleList;
	}

	@Override
	public void characters(char[] ch, int start, int length)
			throws SAXException {
		if (isItem)
			if ( isTitle ) {
				titleList.add( new String( ch, start, length ) );
			}
	}

	@Override
	public void endElement(String uri, String localName, String qName)
			throws SAXException {
		if ( qName.equalsIgnoreCase("item") ) {
			isItem = false;
		}

		if ( qName.equalsIgnoreCase("title") ) {
			isTitle = false;
		}
	}

	@Override
	public void startElement(String uri, String localName, String qName,
			Attributes attributes) throws SAXException {

		if ( qName.equalsIgnoreCase("item") ) {
			isItem = true;
		}

		if ( qName.equalsIgnoreCase("title") ) {
			isTitle = true;
		}

	}

}

Posted by 0xsecret

댓글을 달아 주세요