把请求的参数封装为xml

xiaoxiao2021-02-27  361

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; }
转载请注明原文地址: https://www.6miu.com/read-4194.html

最新回复(0)