我正在构建一个 android 应用程序,我正在尝试解析并且我正在尝试从 rss 提要中解析这个描述标签。
<description>
<![CDATA[
<h1>What Do You Worship?</h1><p>This week <a href="https://twitter.com/#!/nathanielcoon">@Nathanielcoon</a> teaches on the life of Abraham.</a></p> <p><a href="http://www.esvbible.org/search/Genesis+12%3A7-8/">Genesis 12:7-8</a></p> <p><a href="http://www.esvbible.org/search/Genesis+13%3A2-4/">Genes
]]>
<![CDATA[
is 13:2-4</a></p> <p><a href="http://www.esvbible.org/search/Genesis+13%3A14-18/">Genesis 13:14-18</a></p> <p><a href="http://www.esvbible.org/search/Genesis+14%3A17-24/">Genesis 14:17-24</a></p> <p><a href="http://www.esvbible.org/search/Genesis+15%3A1-21/">Genesis 15:1-21</a></p> <p><a href="http://www.esvbible.org/search/Genesis+17%3A3/">Genesis 17:3</a></p> <p><a href="http://www.esvbible.org/search/Genesis+17%3A17/">Genesis 17:17</a></p> <p><a href="http://www.esvbible.org/search/Genesis+18%3A1-33/">Genesis 18:1-33</a></p> <p><a href="http://www.esvbible.org/search/Genesis+21%3A33/">Genesis 21:33</a></p> <p><a href="http://www.esvbible.org/search/Genesis+22%3A4-14/">Genesis 22:4-14</a></p> <p><a href="http://www.esvbible.org/search/Isaiah+44%3A1-20/">Isaiah 44:1-20</a></p> <p><a href="http://www.esvbible.org/search/Revelation+4%3A1-5%3A15/">Revelation 4:1-5:14</a></p> <p><a href="http://www.esvbible.org/search/Isaiah+45%3A20/">Isaiah 45:20</a></p> <p><a href="http://www.esvbible.org/search/Isaiah+45%3A20-22/">Isaiah 45:20-22</a></p> <p><a href="http://www.esvbible.org/search/Matthew+27%3A50-51/">Matthew 27:50-51</a></p> <p><a href="http://www.esvbible.org/search/Mark+15%3A37-38/">Mark 15:37-38</a></p> <p><a href="http://www.esvbible.org/search/Luke+23%3A45-46/">Luke 23:45-46</a></p> <p><a href="http://www.esvbible.org/search/Hebrews+10%3A19/">Hebrews 10:19</a></p> <p><a href="http://www.esvbible.org/search/Isaiah+6%3A1-13/">Isaiah 6:1-13</a></p> <p>For more resources or to contact us visit <a href="http://www.refugecf.com/resources/">RefugeCf.com</a></p> <p>Follow <a href="https://twitter.com/RefugeCF"> @RefugeCF</a> <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script> on Twitter.</p>
但是,我只得到前两行。
<h1>What Do You Worship?</h1><p>This week <a href="https://twitter.com/#!/nathanielcoon">@Nathanielcoon</a> teaches on the life of Abraham.</a></p>
是否有开关或我找不到的东西?我正在为我的 Android 应用程序使用 SAXParser。
还。我尝试解析/获取 itunes:summary 标签,但它根本不起作用。我想知道为什么。
谢谢。
编辑:这是我的 RSSHandler 代码,如果您需要更多病态发布它,但我认为这是我要修复它的地方,其余的只是将它发送到一个活动并查看它。(我在 webview 中查看它。)
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
public class RSSHandler extends DefaultHandler {
final int state_unknown = 0;
final int state_title = 1;
final int state_description = 2;
final int state_link = 3;
final int state_pubdate = 4;
final int state_guid = 5;
final int state_subtitle = 6;
int currentState = state_unknown;
RSSFeed feed;
RSSItem item;
boolean itemFound = false;
RSSHandler(){
}
RSSFeed getFeed(){
return feed;
}
@Override
public void startDocument() throws SAXException {
// TODO Auto-generated method stub
feed = new RSSFeed();
item = new RSSItem();
}
@Override
public void endDocument() throws SAXException {
// TODO Auto-generated method stub
}
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
// TODO Auto-generated method stub
if (localName.equalsIgnoreCase("item")){
itemFound = true;
item = new RSSItem();
currentState = state_unknown;
}
else if (localName.equalsIgnoreCase("title")){
currentState = state_title;
}
else if (localName.equalsIgnoreCase("subtitle")){
currentState = state_subtitle;
}
else if (localName.equalsIgnoreCase("description")){
currentState = state_description;
}
else if (localName.equalsIgnoreCase("link")){
currentState = state_link;
}
else if (localName.equalsIgnoreCase("pubdate")){
currentState = state_pubdate;
}
else if (localName.equalsIgnoreCase("guid")){
currentState = state_guid;
}
else{
currentState = state_unknown;
}
}
@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
// TODO Auto-generated method stub
if (localName.equalsIgnoreCase("item")){
feed.addItem(item);
}
}
@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
// TODO Auto-generated method stub
String strCharacters = new String(ch,start,length);
if (itemFound==true){
// "item" tag found, it's item's parameter
switch(currentState){
case state_title:
item.setTitle(strCharacters);
break;
case state_subtitle:
item.setsubTitle(strCharacters);
break;
case state_description:
item.setDescription(strCharacters);
break;
case state_link:
item.setLink(strCharacters);
break;
case state_pubdate:
item.setPubdate(strCharacters);
break;
case state_guid:
item.setGuid(strCharacters);
break;
default:
break;
}
}
else{
// not "item" tag found, it's feed's parameter
switch(currentState){
case state_title:
feed.setTitle(strCharacters);
break;
case state_subtitle:
feed.setsubTitle(strCharacters);
break;
case state_description:
feed.setDescription(strCharacters);
break;
case state_link:
feed.setLink(strCharacters);
break;
case state_pubdate:
feed.setPubdate(strCharacters);
break;
case state_guid:
feed.setGuid(strCharacters);
break;
default:
break;
}
}
currentState = state_unknown;
}
}