SDomParese.getWeather(url2);
public static void getWeather(String uri) {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
InputStream is = HttpUtils.getInputStremFromXml(uri, "utf-8");
Document document = builder.parse(is);
Element root = document.getDocumentElement();
NodeList list = root.getElementsByTagName("s");
for (int i = 0; i < list.getLength(); i++) {
Element element = (Element) list.item(i);
GlobalConstant.i("k--->>" + element.getAttribute("k"));
GlobalConstant.i("d--->>" + element.getAttribute("d"));
}
} catch (Exception e) {
GlobalConstant.i("dom parse exception-->" + e);
e.printStackTrace();
}
}
/**
*
* 返回inputstream类型的xml数据
*
* @param path
* @param encode
* @return
*/
public static InputStream getInputStremFromXml(String path, String encode) {
HttpClient httpClient = new DefaultHttpClient();
try {
HttpPost httpPost = new HttpPost(path);
HttpResponse httpResponse = httpClient.execute(httpPost);
if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
HttpEntity httpEntity = httpResponse.getEntity();
return httpEntity.getContent();
}
} catch (Exception e) {
System.out.println("get stream exception--->" + e);
e.printStackTrace();
} finally {
httpClient.getConnectionManager().shutdown();
}
return null;
}