我正在尝试解析此LINK的值,其xml编码如下所示
当我尝试获取响应时,在logcat中抛出消息,如下所示
11-19 17:25:13.350: W/System.err(3360): This is not valid URL
11-19 17:25:13.350: W/System.err(3360): java.lang.NullPointerException
当我尝试其他LINK时,其编码是这样的
它工作正常,我可以解析值.
是XML解析失败,因为编码不是UTF-8,所以是utf-8?
我该如何处理.我已经完成了google,并且对XML解析还是陌生的.这是我尝试创建的第一个解析.请让我知道方式.
更新的代码:
public String getXmlFromUrl(String url) {
String xml = null;
try {
// defaultHttpClient
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
xml = EntityUtils.toString(httpEntity);
System.out.println("response -- " + xml);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// return XML
return xml;
}