0

这听起来可能很愚蠢,但我只需要逻辑方面的帮助,我有一个非常简单的 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”等。

我该如何解决这个问题?

4

1 回答 1

2
element.getTextContent();

这将获得所需的文本值。

或者

for (int in = 0; in < numberOfChildren; in++) {
    Node node = nl.item(in);
    Log.d("skt",node.getNodeName() + " = " + node.getTextContent());
    //node.getTextContent() has the text. Add it to map
}
于 2013-09-27T04:03:26.303 回答