Java Reference
In-Depth Information
Display display;
Command backCmd = new Command ("Back", Command.BACK, 0);
class ReadThread extends Thread {
public void run() {
try {
HttpConnection httpConnection =
(HttpConnection) Connector.open (URL);
XmlParser parser = new XmlParser (new
InputStreamReader
(httpConnection.openInputStream()));
parser.skip();
parser.read (Xml.START_TAG, null, "backslash");
while (true) {
parser.skip();
if (parser.peek (Xml.START_TAG, null, "story"))
readStory (parser);
else if (parser.peek (Xml.END_TAG, null,
"backslash")) {
parser.read();
break;
}
else throw new RuntimeException
("XML error: Unexpected event: "+
parser.peek());
}
}
catch (Exception e) {
newsList.append ("Error", null);
descriptions.addElement (e.toString());
}
}
/** Read a story and append it to the list */
void readStory (XmlParser parser) throws IOException {
parser.read (Xml.START_TAG, "", "story");
String title = null;
String description = null;
while (true) {
parser.skip();
ParseEvent event = parser.peek();
if (event.getType() == Xml.START_TAG) {
String name = event.getName();
parser.read();
String text = parser.readText();
parser.read (Xml.END_TAG, "", name);
if (name.equals ("title"))
title = text;
else if (name.equals ("description"))
Search WWH ::




Custom Search