2012-10-03 30 views
1
ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>(); 
XMLParser parser = new XMLParser(); 
String xml = parser.getXmlFromUrl(url); // getting XML 
int displayPerPage = 5; 
int TotalRows = xml.length(); 
Document doc = parser.getDomElement(xml); // getting DOM element 
NodeList nl = doc.getElementsByTagName(KEY_ITEM); 
// looping through all item nodes <item> 

for (int i = 0; i < nl.getLength(); i++) { 
    // creating new HashMap 
    HashMap<String, String> map = new HashMap<String, String>(); 
    Element e = (Element) nl.item(i); 
    // adding each child node to HashMap key => value 
    map.put(KEY_NAME, parser.getValue(e, KEY_NAME)); 
    // adding HashList to ArrayList 
    menuItems.add(map); 
} 

這是我的代碼,我想算節點IM的數量不能夠做到這一點,請告訴我,我怎麼會做http://api.androidhive.info/pizza/?format=xml想這是我的XML,容10項或節點我將如何計算請張貼我的代碼怎麼算(節點列表)的XML項項目的數量

+0

getLength返回列表中的節點數。有效子節點索引的範圍是0到長度-1(含)。它是可用的android自api級別1 –

+0

檢查文檔值,肯定它不爲null.because nl.getLength()給出值10. – mukesh

回答

1

只需使用nl.getLength(),它會返回您的每個標籤中的項目數。

+0

getLength()不存在於構造函數中,當我起訴這 – Anil

+0

getLength()不在構造函數當我* USE – Anil

+0

Thanx我知道了。 – Anil

1

您可以使用類似

NodeList list = doc.getElementsByTagName("item"); 
    System.out.println("Total of elements : " + list.getLength()); 

看看this tutorial

相關問題