0

我有一些以 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):意外令牌(位置:TEXT 1 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;
}
4

0 回答 0