Wednesday, April 28, 2010

List to XML

Iterator it = list.iterator();
while (it.hasNext()) {

Timesheet timesheet = (Timesheet) it.next();

Element row = doc.createElement("Row");
results.appendChild(row);
String columnName = null;

try {
SimpleDateFormat sdf = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
row.appendChild(getElementNode(doc, "RES_ID", Integer
.toString(timesheet.getRES_ID())));

row.appendChild(getElementNode(doc, "FULL_NAME", timesheet
.getFULL_NAME()));

row.appendChild(getElementNode(doc, "RES_UNIQUE_NAME",
timesheet.getRES_UNIQUE_NAME()));

row.appendChild(getElementNode(doc, "RES_OPEN", Integer
.toString(timesheet.getRES_OPEN())));

row.appendChild(getElementNode(doc, "TS_START", sdf.format(
timesheet.getTS_START()).trim()));

row.appendChild(getElementNode(doc, "TS_FINISH", sdf
.format(timesheet.getTS_FINISH()).trim()));

row.appendChild(getElementNode(doc, "TP_ID", timesheet
.getTP_ID()));

row.appendChild(getElementNode(doc, "TP_OPEN", CommonUtils
.convertBooleanToString(timesheet.isTP_OPEN())));

row.appendChild(getElementNode(doc, "RESOURCE_TYPE",
CommonUtils.convertBooleanToString(timesheet
.isRESOURCE_TYPE())));

row.appendChild(getElementNode(doc, "TS_ID", Integer
.toString(timesheet.getTS_ID())));

row.appendChild(getElementNode(doc, "TS_VERSION", Integer
.toString(timesheet.getVersion())));

row.appendChild(getElementNode(doc, "TS_STATUS", Integer
.toString(timesheet.getTS_STATUS())));

row.appendChild(getElementNode(doc, "TS_META_STATUS",
Integer.toString(timesheet.getTS_META_STATUS())));

row.appendChild(getElementNode(doc, "TS_HOURS", Double
.toString(timesheet.getTS_HOURS())));

row.appendChild(getElementNode(doc, "TS_IS_ADJUSTMENT",
CommonUtils.convertBooleanToString(timesheet
.isTS_IS_ADJUSTMENT())));

row.appendChild(getElementNode(doc, "BEING_ADJ",
CommonUtils.convertBooleanToString(timesheet
.isBEING_ADJ())));

row.appendChild(getElementNode(doc, "TS_IS_ADJUSTED",
CommonUtils.convertBooleanToString(timesheet
.isTS_IS_ADJUSTED())));

} catch (Exception ex) {
Element node = doc.createElement(columnName.toUpperCase());
node.appendChild(doc.createTextNode(""));
row.appendChild(node);
}

}

} catch (Exception e) {

e.printStackTrace();

}
return doc;
}

No comments:

Post a Comment