org.apache.harmony.xml.ExpatParser$ParseException:在第292行,第0列



我是XML解析的新手,我需要获取url提要并解析它们,然后将它们保存在本地数据库中。如果我传递其他链接,它会接受,但如果我传递我需要的链接,它会给出这个错误。我还提供了我的代码部分和日志cat输出与此一起。谁能告诉我我面临的是什么问题?

下面是我需要解析的URL。

private static final String POSTS_URL = "http://bgr.in/feed/iphoneapp";

这是产生错误的方法:-

public static void updateStories(Context context, String url, int type) {
    if (StoryService.isConnected(context)) {
        HttpGet request = new HttpGet(url);
        request.addHeader("accepts", "application/rss+xml");
        HttpClient client = new DefaultHttpClient();
        HttpResponse response = null;
        try {
            response = client.execute(request);
        } catch (IOException e) {
            Log.e(TAG, "Failed to get rss feed.", e);
        }
        RootElement root = new RootElement("rss");
        List<BaseStory> stories = Story.appendArrayListener(type, 
                root.getChild("channel"), 0);
        try {
            Xml.parse(response.getEntity().getContent(), Xml.Encoding.UTF_8, root.getContentHandler());
        } catch (Exception e) {
            e.printStackTrace();
            Log.i(TAG, "Failed to parse " + url, e);
        }`public static void updateStories(Context context, String url, int type) {
    if (StoryService.isConnected(context)) {
        HttpGet request = new HttpGet(url);
        request.addHeader("accepts", "application/rss+xml");
        HttpClient client = new DefaultHttpClient();
        HttpResponse response = null;
        try {
            response = client.execute(request);
        } catch (IOException e) {
            Log.e(TAG, "Failed to get rss feed.", e);
        }
        RootElement root = new RootElement("rss");
        List<BaseStory> stories = Story.appendArrayListener(type, 
                root.getChild("channel"), 0);
        try {
            Xml.parse(response.getEntity().getContent(), Xml.Encoding.UTF_8, root.getContentHandler());
        } catch (Exception e) {
            e.printStackTrace();
            Log.i(TAG, "Failed to parse " + url, e);
        }

Log Cat输出如下:—

System.err(19251):  org.apache.harmony.xml.ExpatParser$ParseException: At line 292,column 0: junk after document element
System.err(19251):  at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:515)
System.err(19251):  at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:474)
System.err(19251):  at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:316)
System.err(19251):  at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:279)
System.err(19251):  at android.util.Xml.parse(Xml.java:84)
System.err(19251):  at in.bgr.service.StoryService.updateStories(StoryService.java:122)
System.err(19251):  at in.bgr.service.StoryService.updateStories(StoryService.java:96)
System.err(19251):  at in.bgr.ui.AllStoriesFragment$LoadStoriesTask.doInBackground(AllStoriesFragment.java:309)
System.err(19251):  at in.bgr.ui.AllStoriesFragment$LoadStoriesTask.doInBackground(AllStoriesFragment.java:1)
System.err(19251):  at android.os.AsyncTask$2.call(AsyncTask.java:288)
System.err(19251):  at java.util.concurrent.FutureTask.run(FutureTask.java:237)
System.err(19251):  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
System.err(19251):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)

"junk after document element"错误是由于在XML中根元素标记之后有任何不需要的标记。只是移除根元素标签之后的所有标签。在我的例子中,在XML文件的行号292处有一个重复的XML元素条目。我清除了它,现在我想它会为我工作。

相关内容

  • 没有找到相关文章

最新更新