class GreetingsThread extends Thread {
private final Object itemHandle;
public volatile boolean go = true;
public GreetingsThread(Object itemHandle) {
this.itemHandle = itemHandle;
}
public void main(String argv[]) {
try {
File fXmlFile = new File("scoreboard.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
System.out.println("Sport : " + doc.getDocumentElement().getNodeName());
NodeList nList = doc.getElementsByTagName("matchup");
System.out.println("-----------------------");
for (int temp = 0; temp < nList.getLength(); temp++) {
Node nNode = nList.item(temp);
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
System.out.println(getTagValue("away",eElement));
System.out.println(getTagValue("home",eElement));
System.out.println(getTagValue("score",eElement));
System.out.println(getTagValue("inning",eElement)) ;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
private String getTagValue(String sTag, Element eElement) {
NodeList nlList = eElement.getElementsByTagName(sTag).item(0).getChi ldNodes();
Node nValue = (Node) nlList.item(0);
return nValue.getNodeValue();
}
public void run() {
int c = 0;
Random rand = new Random();
while(go) {
Map<String, String> data = new HashMap<String, String>();
data.put("xmldata", "");
data.put("timestamp", new Date().toString());
listener.smartUpdate(itemHandle, data, false);
c++;
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
}
}
}
}
Bookmarks