для xml как
<items>
<item>
<title>title content </title>
..
</item>
...
</items>
class XMLRSSHandler extends DefaultHandler {
static final String TITLE = "title";
static final String ITEM = "item";
boolean isItem = false;
boolean isTitle = false;
Vector items = new Vector();
String value = "";
private Item currentItem = null;
public XMLRSSHandler() {
}
public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException {
if (name.equalsIgnoreCase(ITEM)) {
currentItem = new Item();
} else if (currentItem != null) {
if (name.equalsIgnoreCase(TITLE)) {
isTitle = true;
}
}
}
public void characters(char[] ch, int start, int length) throws SAXException {
if (isTitle) {
value = new String(ch, start, length).trim();
}
}
public void endElement(String uri, String localName, String name) throws SAXException {
if (isTitle && name.equalsIgnoreCase(TITLE)) {
isTitle = false;
currentItem.setTitle(value);
return;
}
if (currentAItem != null
&& (name.equalsIgnoreCase(ITEM)) {
Logger.debug("Loaded Item " + currentItem.getTitle());
items.addElement(currentArticle);
currentItem= null;
}
}
}