【发布时间】:2012-05-04 16:54:31
【问题描述】:
我正在使用 Android 的 XML 解析助手 (android.util.Xml.parse(InputStream, Encoding, ContentHandler) 来解析这个 RSS 提要:http://www.rssweather.com/wx/nz/christchurch/rss.php。它似乎无法识别 content:encoded 标签,其中包含我要检索的数据。下面是 XML 的结构:
<rss>
<channel>
<item>
<title>...</title>
<pubDate>...</pubDate>
// Other tags
<content:encoded>
<![CDATA[
(.... this is what I want to retrieve ...)
]]>
</content:encoded>
</item>
</channel>
</rsss>
这是我的代码:
void parse(){
RootElement root = new RootElement("rss");
Element channel = root.getChild("channel");
Element item = channel.getChild("item");
Element contentEncoded = item.getChild("content", "encoded");
// Have also tried these two:
Element encoded = item.getChild("encoded");
Element content = item.getChild("content");
contentEncoded.setEndTextElementListener(new EndTextElementListener() {
public void end(String body) {
Log.d("Test", "Content found: " + body);
}
});
try {
Xml.parse(feedUrl.openConnection().getInputStream(),
Xml.Encoding.UTF_8, root.getContentHandler());
} catch (Exception e){
throw new RuntimeException(e);
}
}
我哪里做错了? :) 我可以轻松地从 <item> 元素中检索其他数据,例如标题或 pubDate;只有内容:编码让我无法理解。
【问题讨论】:
-
史蒂夫的问题是由于
<![CDATA[...stackoverflow.com/questions/8193414/parsing-cdata-in-android -
啊哈,这看起来很有趣。我会通读一遍,看看是否能解决问题。谢谢