我尝试从此来源解析xml
以下是我的解析代码:
while (eventType != XmlPullParser.END_DOCUMENT) {
switch (eventType) {
case XmlPullParser.START_TAG:
if (parser.getName().equals("Title")) {
current_tag = tag_title;
deal = new Deals();
}
if (parser.getName().equals("MSRP")) {
current_tag = tag_msrp;
}
if (parser.getName().equals("ConvertedCurrentPrice")) {
current_tag = tag_convertedprice;
}
if (parser.getName().equals("SavingsRate")) {
current_tag = tag_savings;
}
if (parser.getName().equals("SmallPictureURL")) {
current_tag = tag_icon;
}
break;
case XmlPullParser.END_TAG:
if (parser.getName().equals("Item")) {
current_tag = -1;
deals.add(deal);
}
break;
case XmlPullParser.TEXT:
String value = parser.getText();
switch (current_tag) {
case tag_title:
deal.setTitle(value);
break;
case tag_msrp:
deal.setMSRP(value);
break;
case tag_convertedprice:
deal.setconvertedPrice(value);
break;
case tag_savings:
deal.setSavings(value);
break;
case tag_icon:
System.out.println("Icon for the current deal is: "+value);
deal.setIcon(value);
break;
default:
break;
}
current_tag = -1;
break;
}
eventType = parser.next();
}
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
在这一行eventType = parser.next()
,我得到以下异常:
07-19 10:43:23.262: W/System.err(922): org.xmlpull.v1.XmlPullParserException: expected: /link read: head (position:END_TAG </head>@1:427 in java.io.InputStreamReader@40dee498)
07-19 10:43:23.272: W/Trace(922): Unexpected value from nativeGetEnabledTags: 0
07-19 10:43:23.272: W/Trace(922): Unexpected value from nativeGetEnabledTags: 0
07-19 10:43:23.282: W/System.err(922): at org.kxml2.io.KXmlParser.readEndTag(KXmlParser.java:970)
07-19 10:43:23.282: W/System.err(922): at org.kxml2.io.KXmlParser.next(KXmlParser.java:372)
07-19 10:43:23.282: W/System.err(922): at org.kxml2.io.KXmlParser.next(KXmlParser.java:310)
07-19 10:43:23.282: W/System.err(922): at com.nykkos.dailydeals.Parsers.parseDeals(Parsers.java:91)
07-19 10:43:23.282: W/System.err(922): at com.nykkos.dailydeals.WebServices.downloadDeals(WebServices.java:37)
07-19 10:43:23.282: W/System.err(922): at com.nykkos.dailydeals.DealsActivity.run(DealsActivity.java:59)
我没有找到任何明显的原因来解释为什么会发生这种情况。
非常感谢解决此问题的任何帮助。