|
xxxx
/**
* 写xml
* Please write comments here
*/
public static void ProcessWriter(String startTime, String endTime, String partState) {
String xmlpath = "C:\\process.xml";
try {
//Document
Element root = new Element("Root" ;
Document doc = new Document(root);
Map<HuaweiPart, Map<String, String>> partMap = getPartByCondition(startTime,endTime, partState);
System.out.println("step into...." ;
for (Iterator<HuaweiPart> iterMap = partMap.keySet().iterator(); iterMap.hasNext() {
Element partEle = new Element("Part" ;
root.addContent(partEle);
HuaweiPart part1 = (HuaweiPart) iterMap.next();
Map<String, String> ibavalue = partMap.get(part1);
partEle.setAttribute("name", part1.getName());
partEle.setAttribute("number", part1.getNumber());
partEle.setAttribute("createtime",part1.getCreateTimestamp().toString());
//遍历iba
for (Iterator<String> ibaMap = ibavalue.keySet().iterator(); ibaMap.hasNext() {
Element ibaEle = new Element("Iba" ;
partEle.addContent(ibaEle);
String key = ibaMap.next();
ibaEle.setAttribute(key,ibavalue.get(key).toString());
}
}
XMLOutputter outputter = new XMLOutputter();
outputter.setEncoding("utf-8" ;
outputter.output(doc, new FileOutputStream(xmlpath));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} |
|