您的問題在於,XML節點必須以字母開頭 - 就像Java中的變量一樣。你可以試試下面的:
<items>
<item name="box" price="2.00" />
<item name="pencil" price="1.00" />
</items>
所以你看,每個item
被表示爲<item>
。在XML中,標籤具有語義意義。您可以將它們這樣做(取決於你的分析器 - 這是實際上更接近JavaScript,但我希望你能明白我的意思):
myXmlDocument = parseThatXMLForMePlease(); // Load the XMl from wherever
itemList = myXmlDocument.getChildren()[0]; // Get the first node in the document
firstItem = itemList.getChildren()[0]; // Get the first child of the item list
itemName = firstItem.getAttr("name");
itemPrice = firstItem.getAttr("price");
如果你想利用這些數據爲基礎,一些列表框,你可能會想要使用Adapter。這基本上是一個數據結構,用於爲一些UI小部件提供數據(鏈接指向一個ListAdapter - 這聽起來像是你想要的)。