1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
InputStream result12voipXMLStream = getUrlDataStream(my12voipURL);
//displayAlert("DEBUG", result12voipXML);
/* Get a SAXParser from the SAXPArserFactory. */
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
/* Get the XMLReader of the SAXParser we created. */
XMLReader xr = sp.getXMLReader();
/* Create a new ContentHandler and apply it to the XML-Reader*/
SMSResponseHandler xmlHandler = new SMSResponseHandler();
xr.setContentHandler(xmlHandler);
/* Parse the xml-data from our URL. */
xr.parse(new InputSource(result12voipXMLStream));
//xr.parse(new InputSource(my12voipURL));
/* Parsing has finished. */
/* Our ExampleHandler now provides the parsed data to us. */
ParsedSMSResponseDataSet parsedExampleDataSet =xmlHandler.getParsedData();
...
public InputStream getUrlDataStream(String url) {
try {
HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, 1000*60*2);
HttpConnectionParams.setSoTimeout(httpParams, 1000*60*2);
DefaultHttpClient client = new DefaultHttpClient(httpParams);
//DefaultHttpClient client = new DefaultHttpClient();
URI uri = new URI(url);
HttpGet method = new HttpGet(uri);
HttpResponse res = client.execute(method);
return res.getEntity().getContent();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
}
return null;
} |