我是 XML 解析的新手,我需要获取 url 提要并解析它们,然后将它们保存在本地数据库中。如果我传递了它接受的其他链接,但如果我传递了我需要的链接,则会出现此错误。我还提供了我的代码部分和日志猫输出。谁能告诉我我面临什么样的问题?
以下是我需要解析的 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)