0
我將如何返回/解析具有特定值的節點元素。Android根據日期值解析XML
下面是我簡單的XML,但我只需要time
,meeting_name
和host_name
從具有的2012-03-09
日期的meeting_item
的:
<meeting_item>
<time>12:30</time>
<date>2012-03-09</date>
<meeting_name>build a shop 4</meeting_name>
<host_name>Bob Jones</host_name>
</meeting_item>
<meeting_item>
<time>11:30</time>
<date>2012-03-23</date>
<meeting_name>build a shop advance</meeting_name>
<host_name>Judy Washington</host_name>
</meeting_item>
<meeting_item>
<time>11:30</time>
<date>2012-03-23</date>
<meeting_name>build a shop 2</meeting_name>
<host_name>Tom Smith</host_name>
</meeting_item>
<meeting_item>
<time>11:30</time>
<date>2012-04-06</date>
<meeting_name>build a shop 3</meeting_name>
<host_name>Tom Green</host_name>
</meeting_item>
下面是我的解析代碼,但迄今爲止這只是得到一切都在文件中:
String xml = XMLfunctions.getXML(items);
Log.d(TAG, xml);
Document doc = XMLfunctions.XMLfromString(xml);
int numResults = XMLfunctions.numResults(doc);
if((numResults <= 0)){
Toast.makeText(MeetingManager.this, "NOT GETTING XML", Toast.LENGTH_LONG).show();
finish();
}
Element docElem = doc.getDocumentElement();
NodeList nl = docElem.getElementsByTagName("Meeting_Data");
Element elem = (Element)nl.item(1);
NodeList nodes = elem.getElementsByTagName("meeting_item");
for (int i = 0; i < nodes.getLength(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element)nodes.item(i);
map.put("time", XMLfunctions.getValue(e, "time"));
map.put("name", XMLfunctions.getValue(e, "meeting_name"));
map.put("hostname", XMLfunctions.getValue(e, "host_name"));
mylist.add(map);
}
ListAdapter adapter = new SimpleAdapter(MeetingManager.this, mylist , R.layout.listlayout,
new String[] {"time", "name", "hostname" },
new int[] { R.id.time, R.id.meeting_name, R.id.host });
setListAdapter(adapter);
而且在我的logcat Log.d(TAG,XML);並不能完成整個文件。有時會拋出錯誤而不讀取所有文件。有沒有限制我可以httpGet?