【发布时间】:2018-09-20 23:59:45
【问题描述】:
这是我尝试使用 XmlPullParser 在 Android Java 中读取的 XML,但我找不到读取 <link/> 标记的方法,因为它是自封闭标记
<id>
tag:google.com,2013:googlealerts/feed:10407958590599670710
</id>
<title type="html">
Uhuru's order on fare control has no legal backing
</title>
<link href="https://www.google.com/url?rct=j&sa=t&url=https://www.nation.co.ke/business/Uhuru-s-order-on-fare-control-has-no-legal-backing/996-4768072-coxlk6z/index.html&ct=ga&cd=CAIyHDI1YTNhOGJmZjY3ZmQ4NTk6Y29tOmVuOktFOlI&usg=AFQjCNG10EpkC5Gogga5T4Hkys8pg3TCHw"/>
<published>2018-09-19T18:11:15Z</published>
<updated>2018-09-19T18:11:15Z</updated>
<content type="html">
Lawyers, matatu operators and
<b>NTSA</b> sources said that the transport ... transport sector — said
<b>NTSA</b> has no legal mandate to set fares, adding that ...
</content>
<author>
<name/>
</author>
这是我的 java 代码 sn-p 试图通过 xml 归档读取
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG) {
if (xpp.getName().equalsIgnoreCase("entry")) {
insideItem = true;
} else if (xpp.getName().equalsIgnoreCase("title")) {
if (insideItem) {
titles.add(xpp.nextText());
}
} else if (xpp.getName().equalsIgnoreCase("link")) {
if (insideItem) {
links.add(xpp.nextText());
}
} else if (xpp.getName().equalsIgnoreCase("content")) {
if (insideItem) {
content.add(xpp.nextText());
}
} else if (xpp.getName().equalsIgnoreCase("published")) {
if (insideItem) {
published.add(xpp.nextText());
}
}
} else if (eventType == XmlPullParser.END_TAG &&
xpp.getName().equalsIgnoreCase("entry")) {
insideItem = false;
}
eventType = xpp.next();
}
【问题讨论】:
标签: android xml xml-parsing xmlpullparser