我正在嘗試從RSS源中檢索數據。我的程序運行良好,只有一個例外。 飼料具有的結構如下項目:解析Android應用程序中的RSS源
<title></title>
<link></link>
<description></description>
我可以檢索數據,但是當標題具有「&」字符字符串的字符之前返回停止。因此,例如,這個標題:
<title>A&T To Play Four Against Bears</title>
我只取回的「A」,當我想到要回「A &噸至打四對抗熊」。
誰能告訴我,如果我可以修改我的現有RSSReader類佔的&放大器的存在:
import android.util.Log;
進口的java.net.URL; import java.util.ArrayList; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.CharacterData; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList;
公共RSSReader類{
private static RSSReader instance = null;
private RSSReader() {
}
public static RSSReader getInstance() {
if (instance == null) {
instance = new RSSReader();
}
return instance;
}
public ArrayList<Story> getStories(String address) {
ArrayList<Story> stories = new ArrayList<Story>();
try {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
URL u = new URL(address);
Document doc = builder.parse(u.openStream());
NodeList nodes = doc.getElementsByTagName("item");
for (int i = 0; i < nodes.getLength(); i++) {
Element element = (Element) nodes.item(i);
Story currentStory = new Story(getElementValue(element, "title"),
getElementValue(element, "description"),
getElementValue(element, "link"),
getElementValue(element, "pubDate"));
stories.add(currentStory);
}//for
}//try
catch (Exception ex) {
if (ex instanceof java.net.ConnectException) {
}
}
return stories;
}
private String getCharacterDataFromElement(Element e) {
try {
Node child = e.getFirstChild();
if (child instanceof CharacterData) {
CharacterData cd = (CharacterData) child;
return cd.getData();
}
} catch (Exception ex) {
Log.i("myTag2", ex.toString());
}
return "";
} //private String getCharacterDataFromElement
protected float getFloat(String value) {
if (value != null && !value.equals("")) {
return Float.parseFloat(value);
} else {
return 0;
}
}
protected String getElementValue(Element parent, String label) {
return getCharacterDataFromElement((Element) parent.getElementsByTagName(label).item(0));
}
}
如何解決這個任何想法?
你能給的鏈接RSS訂閱? – 2012-04-21 18:23:51
sure:http://www.ncataggies.com/rss.dbml?db_oem_id=24500&RSS_SPORT_ID=74515&media=news – 2012-04-21 18:25:32
我在想這可能是數據從標題標籤中提取的方式 – 2012-04-21 18:26:26