我试图解析RSS Feed,当我读取数据时,我得到的是名称空间URL而不是值。
public void readRss() {
try {
URL url = new URL("http://olemisssports.com/calendar.ashx/calendar.rss?sport_id=0");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept","application/xml + rss");
conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 4.01; Windows NT)");
SyndFeedInput input = new SyndFeedInput();
XmlStreamReader xmlStReader = new XmlStreamReader(conn.getInputStream());
SyndFeed feed = input.build(xmlStReader);
for (Iterator iterator = feed.getEntries().iterator(); iterator.hasNext();) {
ArrayList fields = (ArrayList) syndEntry.getForeignMarkup();
for (int i = 0; i < fields.size(); i++) {
System.out.println("field: " + fields.get(i));
}
}
}
返回值如下所示。
field: [Element: <ev:location [Namespace: http://purl.org/rss/1.0/modules/event/]/>]
field: [Element: <ev:startdate [Namespace: http://purl.org/rss/1.0/modules/event/]/>]
field: [Element: <ev:enddate [Namespace: http://purl.org/rss/1.0/modules/event/]/>]
field: [Element: <s:localstartdate [Namespace: http://sidearmsports.com/schemas/cal_rss/1.0/]/>]
field: [Element: <s:localenddate [Namespace: http://sidearmsports.com/schemas/cal_rss/1.0/]/>]
另一方面,实际数据看起来像..
<ev:location>Oxford, Miss.</ev:location>
<ev:startdate>2019-05-11T23:00:00.0000000Z</ev:startdate>
<ev:enddate>2019-05-12T02:00:00.0000000Z</ev:enddate>
<s:localstartdate>2019-05-11T18:00:00.0000000</s:localstartdate>
<s:localenddate>2019-05-11T21:00:00.0000000</s:localenddate>
我想知道为什么要找回这些命名空间URI而不是文字值,我需要在代码中做些什么?