我正在尝试解析此XML文件,但START_TAG收到错误。 我应该如何设置START_TAG到此XML文件的名称
org.xmlpull.v1.XmlPullParserException: expected: START_TAG {null}rss version="2.0" (position:START_TAG <rss version='2.0'>@2:20 in java.io.InputStreamReader@3a7a4ee3)
public ArrayList<Article> parse(InputStream is) throws XmlPullParserException, IOException, ParseException {
try {
XmlPullParser parser = Xml.newPullParser();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
parser.setInput(is, null);
parser.nextTag();
return readFeed(parser);
} finally {
is.close();
}
}
private ArrayList<Article> readFeed(XmlPullParser parser) throws IOException, XmlPullParserException, ParseException {
ArrayList<Article> articles = new ArrayList<>();
parser.require(XmlPullParser.START_TAG,ns,"rss version=\"2.0\"");
while (parser.next() != XmlPullParser.END_TAG) {
if (parser.getEventType() != XmlPullParser.END_TAG) {
continue;
}
String name = parser.getName();
// Starts by looking for the entry tag
if (name.equals("item")) {
articles.add(readEntry(parser));
} else {
skip(parser);
}
}
return articles;
}
这是XML文件的链接
答案 0 :(得分:0)
想出我的START_TAG需要:
sm = difflib.SequenceMatcher(None,list(ya),list(yb))
sm.ratio()
我还需要另一个while循环
parser.require(XmlPullParser.START_TAG,ns,"rss");
while (parser.next() != XmlPullParser.END_TAG)