0
我正在使用此方法從遠程服務器獲取xml文件,我使用另一個解析器類來解析它,並且它已成功解析。但是,當我使用Log.d("get xml", xml)
來檢查xml文件的內容時,它只在logCat中顯示<?xml version="1.0" standalone="no"?>
。爲什麼?爲什麼我只需要獲取<?xml version =「1.0」standalone =「no」?>何時請求一個xml文件? Android
public String getXmlFromUrl(String url) {
String xml = null;
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
if(httpPost != null){
Log.d("httpPost", "httpPost not null");
}
HttpResponse httpResponse = httpClient.execute(httpPost);
if(httpResponse != null){
Log.d("httpResponse", "httpResponse not null");
}
HttpEntity httpEntity = httpResponse.getEntity();
xml = EntityUtils.toString(httpEntity);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// return XML
Log.d("get xml", xml);
if(xml!=null){
Log.d("get http client", "get http client not null");
}
return xml;
}