dom4j 生成完整xml标签内容
程序员文章站
2022-07-13 15:49:52
...
dom4j生成xml,如果标签内容为空,会简化便签,例如 <name />
但是会影响加签验签,需要生成完整的标签 <name></name>
但是会影响加签验签,需要生成完整的标签 <name></name>
SAXReader saxReader = new SAXReader(); Document document = saxReader.read(new ByteArrayInputStream(message.getBytes("UTF-8"))); Iterator orderIt = document.selectNodes("/CMBCPayRes/MsgBody").iterator(); Element elem = null; while (orderIt.hasNext()) { elem = (Element) orderIt.next(); } OutputFormat xmlFormat = new OutputFormat(); xmlFormat.setExpandEmptyElements(true); StringWriter sw = new StringWriter(); XMLWriter xmlWriter = new XMLWriter(sw,xmlFormat); xmlWriter.write(elem); xmlWriter.close(); return sw.toString();
上一篇: 表单字段类型转化
下一篇: dataTables 多条件查询 自定义