Java Reference
In-Depth Information
public void elementStart (String name, Hashtable attributes)
{
currentElement = name;
if (name.equals ("story")) {
title = new StringBuffer();
description = new StringBuffer();
}
}
public void charData (String s) {
if (currentElement.equals ("title"))
title.append (s);
else if (currentElement.equals ("description"))
description.append (s);
}
public void elementEnd (String name){
currentElement ="";
if (name.equals ("story ")){
newsList.append (title.toString(),null);
String d =description.toString();
descriptions.addElement
(d.length()==0 ?title.toString():d);
}
}
public void readNews() {
try {
HttpConnection httpConnection =
(HttpConnection) Connector.open (URL);
InputStream is = httpConnection.openInputStream();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte [] buf = new byte [256];
while (true) {
int cnt = is.read (buf, 0, 256);
if (cnt < 0) break;
bos.write (buf, 0, cnt);
}
XMLParser parser = new XMLParser();
parser.setInputStream
(new XMLInputStream (new String (bos.toByteArray())));
parser.setDocumentHandler (new NewsHandler());
parser.parse();
}
catch (ParseException e) {
newsList.append ("Error", null);
descriptions.addElement (e.toString());
}
catch (IOException e) {
newsList.append ("Error", null);
descriptions.addElement (e.toString());
}
}
public void startApp() {
Search WWH ::




Custom Search