public String generateXML(ReqMap headesr) {
try {
Element ele= toXML(header);
Document document = DocumentHelper.createDocument();
Element root = document.addElement("beans");
root.add(ele);//往<beans></beans>中添加元素
return document.asXML();
}catch(Exception ex) {
logger.error("generateXML ex:"+ ex);
return null;
}
public static Element toXML(ReqMap header) throws Exception {
Element ele = DocumentHelper.createElement("head");
if (header.getType() != 0) {
el.addElement("type").setText(Integer.toString(header.getType()));
}
el.addElement("action").setText(Integer.toString(header.getAction()));
if (header.getVersion() != 0) {
el.addElement("version").setText(String.valueOf(header.getVersion()));
}
if (header.getId() != null) {
el.addElement("id").setText(header.getId());
}
if (null != header.getPhone()) {
el.addElement("phone").setText(header.getPhone());
}
return ele;
}