11 |
import javax.xml.parsers.DocumentBuilderFactory; |
import javax.xml.parsers.DocumentBuilderFactory; |
12 |
import javax.xml.parsers.ParserConfigurationException; |
import javax.xml.parsers.ParserConfigurationException; |
13 |
|
|
14 |
|
|
15 |
import org.w3c.dom.Document; |
import org.w3c.dom.Document; |
16 |
import org.w3c.dom.Node; |
import org.w3c.dom.Node; |
17 |
import org.w3c.dom.NodeList; |
import org.w3c.dom.NodeList; |
26 |
static final int WIDTH = 450; |
static final int WIDTH = 450; |
27 |
static final String BASEURL = "http://apps.todic.net/side9/"; |
static final String BASEURL = "http://apps.todic.net/side9/"; |
28 |
|
|
29 |
public static Document parseXML(String str) throws SAXException, IOException, ParserConfigurationException |
public static Document parseXML(byte data[]) throws SAXException, IOException, ParserConfigurationException |
30 |
{ |
{ |
31 |
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); |
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); |
32 |
return builder.parse( new ByteArrayInputStream(str.getBytes()) ); |
|
33 |
|
return builder.parse( new ByteArrayInputStream( data) ); |
34 |
} |
} |
35 |
|
|
36 |
|
|
37 |
public static byte[] getContent(String uri) throws IOException { |
public static byte[] getContent(String uri) throws IOException { |
38 |
byte buffer[] = new byte[256]; |
byte buffer[] = new byte[256]; |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
ByteArrayOutputStream baos = new ByteArrayOutputStream(32768); //start buffer size - instead of default 32bytes |
ByteArrayOutputStream baos = new ByteArrayOutputStream(32768); //start buffer size - instead of default 32bytes |
43 |
|
|
44 |
URL url = new URL(uri); |
URL url = new URL(uri); |
64 |
public static Side9Data loadXml() throws IOException, ParserConfigurationException, SAXException{ |
public static Side9Data loadXml() throws IOException, ParserConfigurationException, SAXException{ |
65 |
String dataURL = BASEURL + "xml.php?width=" + WIDTH; |
String dataURL = BASEURL + "xml.php?width=" + WIDTH; |
66 |
|
|
67 |
byte data[] = getContent( dataURL ); |
byte data[] = getContent( dataURL ); |
68 |
String xmlData = new String(data, "ISO-8859-1"); |
Document doc = parseXML( data ); |
|
Document doc = parseXML(xmlData); |
|
69 |
|
|
70 |
Node rootNode = doc.getDocumentElement(); // stations |
Node rootNode = doc.getDocumentElement(); // stations |
71 |
NodeList nodes = rootNode.getChildNodes(); |
NodeList nodes = rootNode.getChildNodes(); |