我试图多次获取 FL 标签,但是当我尝试内部节点列表时,它只获取第一项。有关更多信息,请参阅我的输出。这是我从 Web 服务获得的 XML 数据
<response uri="/ats/private/xml/JobOpenings/getRecords">
<result>
<JobOpenings>
<row no="1">
<FL val="JOBOPENINGID">
<![CDATA[ 100 ]]>
</FL>
<FL val="Published in website">
<![CDATA[ true ]]>
</FL>
<FL val="Modified by">
<![CDATA[ Admmin ]]>
</FL>
<FL val="Modified time">
<![CDATA[ Yesterday ]]>
</FL>
</row>
<row no="2">
<FL val="JOBOPENINGID">
<![CDATA[ 101 ]]>
</FL>
<FL val="Published in website">
<![CDATA[ true ]]>
</FL>
<FL val="Modified by">
<![CDATA[ Admin ]]>
</FL>
<FL val="Modified time">
<![CDATA[ 2 Days Ago ]]>
</FL>
</row>
<row no="3">
<FL val="JOBOPENINGID">
<![CDATA[ 102 ]]>
</FL>
<FL val="Published in website">
<![CDATA[ true ]]>
</FL>
<FL val="Modified by">
<![CDATA[ Admin ]]>
</FL>
<FL val="Modified time">
<![CDATA[ 2 Days Ago ]]>
</FL>
</row>
<JobOpenings>
<result>
</response>
这是我在活动中使用的代码
public class AndroidXMLParsingActivity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
XMLParser parser = new XMLParser();
String xml = parser.getXmlFromUrl(AppConfig.URL); // getting XML
Document doc = parser.getDomElement(xml); // getting DOM element
NodeList nodeList = doc.getElementsByTagName("row");
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
Element playlistElement = (Element) node;
NodeList title = playlistElement.getElementsByTagName("FL");
for (int kl = 0; kl < title.getLength(); kl++) {
if (title.item(0).getChildNodes().item(0) != null) {
Element nameElement = (Element) title.item(0);
title = nameElement.getChildNodes();
Log.v("name===>", ((Node) title.item(0)).getNodeValue());
}
}
}
}
}
这是输出:
12-04 15:56:08.694: V/name===>(3918): JOBOPENINGID 100
12-04 15:56:08.694: V/name===>(3918): JOBOPENINGID 101
12-04 15:56:08.704: V/name===>(3918): JOBOPENINGID 102
12-04 15:56:08.704: V/name===>(3918): JOBOPENINGID 103
12-04 15:56:08.704: V/name===>(3918): JOBOPENINGID 107
12-04 15:56:08.704: V/name===>(3918): JOBOPENINGID 108
12-04 15:56:08.704: V/name===>(3918): JOBOPENINGID 118
12-04 15:56:08.704: V/name===>(3918): JOBOPENINGID 200
请帮帮我............