我有一些以UTF-8编码的.xml文件。但每当我尝试在Eclipse上解析它时 我的应用程序无法运行,
我的xml文件
<?xml version="1.0" encoding="UTF-8"?>
<music>
<song>
<id>1</id>
<title>Someone Like You</title>
<artist>Adele</artist>
<duration>4:47</duration>
<thumb_url>http://api.androidhive.info/music/images/adele.png</thumb_url>
</song>
</music>
我收到此错误:
E /错误:(540):意外的令牌(位置:TEXT1 in java.io.StringReader@412d05e0) E / AndroidRuntime(540):致命异常:主
虽然我已经在网上找到的另一个xml链接上进行了测试,但它工作得很好!!
public XMLParser() {
}
/**
* Getting XML from URL making HTTP request
* @param url string
* */
public String getXmlFromUrl(String url) {
String xml = null
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpGet);
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
return xml;
}