这听起来可能很愚蠢,但我只需要逻辑方面的帮助,我有一个非常简单的 XML 数组:
<plist version="1.0">
<array>
<string>Lisa Jackson</string>
<string>Elisabeth Hartmann</string>
<string>C. J. Sansom</string>
<string>Irmengard Gabler</string>
<string>Oliver Pötzsch</string>
<string>Ulla Illerhaus</string>
<string>Christopher J. Sansom</string>
<string>Nina Blazon</string>
<string>Nicholas Lessing</string>
<string>Johannes Steck</string>
<string>Peter Kaempfe</string>
<string>Dimeter Inkiow</string>
<string>Barbara Sher</string>
<string>Ulrike Hübschmann</string>
<string>Otfried Preußler</string>
<string>Ulla Illerhaus</string>
<string>Annette Kurth</string>
</array>
</plist>
但是当我尝试以这种方式解析它时:
static final String KEY_ITEM = "string";
ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();
XMLParser parser = new XMLParser();
String xml = parser.getXmlFromUrl(URL); // getting XML
Document doc = parser.getDomElement(xml); // getting DOM element
NodeList nl = doc.getElementsByTagName(KEY_ITEM);
for (int i = 0; i < nl.getLength(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) nl.item(i);
map.put(KEY_ITEM, parser.getValue(e, KEY_ITEM));
menuItems.add(map);
}
它根据 XML 文件中给定的数量(17 个列表项)显示列表,但不显示任何内容,如“Lisa Jackson”、“Elisabeth Hartmann”等。
我该如何解决这个问题?