11 |
import javax.xml.parsers.DocumentBuilderFactory; |
import javax.xml.parsers.DocumentBuilderFactory; |
12 |
import javax.xml.parsers.ParserConfigurationException; |
import javax.xml.parsers.ParserConfigurationException; |
13 |
|
|
14 |
|
import org.apache.http.HttpResponse; |
15 |
|
import org.apache.http.client.HttpClient; |
16 |
|
import org.apache.http.client.methods.HttpGet; |
17 |
|
import org.apache.http.impl.client.DefaultHttpClient; |
18 |
import org.w3c.dom.Document; |
import org.w3c.dom.Document; |
19 |
import org.w3c.dom.Node; |
import org.w3c.dom.Node; |
20 |
import org.w3c.dom.NodeList; |
import org.w3c.dom.NodeList; |
32 |
public static Document parseXML(String str) throws SAXException, IOException, ParserConfigurationException |
public static Document parseXML(String str) throws SAXException, IOException, ParserConfigurationException |
33 |
{ |
{ |
34 |
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); |
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); |
35 |
|
|
36 |
return builder.parse( new ByteArrayInputStream(str.getBytes()) ); |
return builder.parse( new ByteArrayInputStream(str.getBytes()) ); |
37 |
} |
} |
38 |
|
|
40 |
public static byte[] getContent(String uri) throws IOException { |
public static byte[] getContent(String uri) throws IOException { |
41 |
byte buffer[] = new byte[256]; |
byte buffer[] = new byte[256]; |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
ByteArrayOutputStream baos = new ByteArrayOutputStream(32768); //start buffer size - instead of default 32bytes |
ByteArrayOutputStream baos = new ByteArrayOutputStream(32768); //start buffer size - instead of default 32bytes |
46 |
|
|
47 |
URL url = new URL(uri); |
URL url = new URL(uri); |
69 |
|
|
70 |
byte data[] = getContent( dataURL ); |
byte data[] = getContent( dataURL ); |
71 |
String xmlData = new String(data, "ISO-8859-1"); |
String xmlData = new String(data, "ISO-8859-1"); |
72 |
|
xmlData = xmlData.replace("encoding=\"ISO-8859-1\"", ""); |
73 |
|
|
74 |
Document doc = parseXML(xmlData); |
Document doc = parseXML(xmlData); |
75 |
|
|
76 |
Node rootNode = doc.getDocumentElement(); // stations |
Node rootNode = doc.getDocumentElement(); // stations |