Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/211.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基于android的xml解析器_Android_Xml - Fatal编程技术网

基于android的xml解析器

基于android的xml解析器,android,xml,Android,Xml,我有一些用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>

我有一些用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>

您的XML文件中似乎有一个无法识别的字符,导致解析器崩溃。下面是我的XML,您需要将XML简化为一个小示例来说明问题,然后在问题中包含该XML,而不是作为链接,而是作为问题的一部分。这是因为你的问题应该是独立的;使用包含重要内容的外部站点的链接,如果外部内容不可用,则您的问题将变得毫无意义。此外,重要内容的非现场发布使得SO的未来用户无法对其进行搜索。请编辑您的问题以将其包括在内,您可能还想快速回顾。我已通过将编码更改为解决了我的问题
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;
}