如何從以下XML-Tag提取url = ""
零件。我在Android中使用Jsoup
。如何在jsoup中提取屬性
<enclosure type="image/jpg" url="EXTRACT THIS" length="123456" />
見我的代碼:
Document doc = db.parse(new InputSource(url.openStream()));
doc.getDocumentElement().normalize();
// Get all <item> tags.
NodeList nl = doc.getElementsByTagName("item");
int length = nl.getLength();
for (int i = 0; i < length; i++) {
Node currentNode = nl.item(i);
RSSItem _item = new RSSItem();
NodeList nchild = currentNode.getChildNodes();
int clength = nchild.getLength();
// Get the required elements from each Item
for (int j = 0; j < clength; j = j + 1) {
Node thisNode = nchild.item(j);
String theString = null;
String nodeName = thisNode.getNodeName();
//NodeList test = nchild.item(j).getChildNodes();
if(j<=3){
theString = nchild.item(j).getFirstChild().getNodeValue();
}
if("enclosure".equals(nodeName)){
//HAVE TO GET URL HERE from ATTRIBUTE:
}
這是XML:
view-source:http://www.skysports.com/rss/0,20514,11661,00.xml
我已經看了看這個鏈接。它沒有幫助。我是Android新手 –