我已经为 Blackberry java 开发了 RssParser,并且我成功地从 Rss xml 文件中解析了标题,但我的要求是也解析来自 Rss 的 imageurls。
但是我的代码对单个标签运行良好,我的实际要求在drawlist
方法中。如何从 Rss 中检索图像 url 和标题标签值?
这是我的代码:
public void run() {
Document doc;
StreamConnection conn = null;
InputStream is = null;
try {
conn = (StreamConnection) Connector.open("Rss.xml"+";deviceside=true");
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
docBuilderFactory.setIgnoringElementContentWhitespace(true);
docBuilderFactory.setCoalescing(true);
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
docBuilder.isValidating();
is = conn.openInputStream();
doc = docBuilder.parse(is);
doc.getDocumentElement().normalize();
NodeList list = doc.getElementsByTagName("image");
NodeList list = doc.getElementsByTagName("title");
for (int a = 0; a < list.getLength(); a++) {
Node textNode1 = list.item(a).getFirstChild();
listElements.addElement(textNode.getNodeValue());
}
public void drawListRow(ListField list, Graphics g, int index, int y, int w)
{
String title = (String)listElements.elementAt(index);
g.drawText(title, 5, 15+y, 0, w);
}