-2
我有一個XML文件,其中包含多個有子節點的節點。如果節點具有相同的密鑰,則其子節點必須合併到一個節點中。基於密鑰將XML節點合併爲一個
<availexport>
<date>090423121513</date>
<employee emp_cd="9120004">
<day date="20050406" start="10" end="20"/>
<day date="20050406" start="21" end="23"/>
<day date="20050511" start="12" end="23"/>
</employee>
<records>3</records>
</availexport>
這裏有兩條記錄有相同的日期。我怎樣才能將它們合併成一個?我有這些鍵/值對的列表。
for (int k = this.employeesList.size(); k > 0; k--) {
Map empInfo1 = new HashMap();
Map empInfo = (Map) this.employeesList.remove(0);
this.empID = (Long) empInfo.get(EMP_ID);
this.hrID = (String) empInfo.get(HR_EMP_ID);
this.avail_iDate = (Long) empInfo.get(AVAIL_IDATE);
this.start_ITime = (Long) empInfo.get(START_ITIME);
this.end_ITime = (Long) empInfo.get(END_ITIME);
List availList = new ArrayList();
Map availList1 = new HashMap();
if (empAvailRecord.containsKey(empID)) {
empInfo1 = (Map) empAvailRecord.get(empID);
availList = (List) empInfo1.get("DAY");
availList1.put(AVAIL_IDATE, avail_iDate);
availList1.put(START_ITIME, start_ITime);
availList1.put(END_ITIME, end_ITime);
availList.add(availList1);
} else {
availList1.put(AVAIL_IDATE, avail_iDate);
availList1.put(START_ITIME, start_ITime);
availList1.put(END_ITIME, end_ITime);
availList.add(availList1);
empInfo1.put("HR_ID", hrID);
empInfo1.put("DAY", availList);
empAvailRecord.put(empID, empInfo1);
}
}
我在這裏實際上沒有看到問題嗎? – AnthonyWJones 2009-04-23 07:17:29
不,我想解釋它的細節,所以粘貼代碼 在簡單的如何將兩個重複節點合併爲一個 – GustyWind 2009-04-23 07:24:38