$使用dom4j可解析 返回&#x等字样的 html转义字符
2024-10-19 02:18:59
如果以GET或POST请求某个系统返回,带有 $#x 那很有可能是axis服务器返回的.
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><validateInvoiceResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><validateInvoiceReturn xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">{"returncode":"10006","returnmsg":"未获取到交易机构信息","fpdm":"null","fphm":"null","kprq":"null"}
</validateInvoiceReturn></validateInvoiceResponse></soapenv:Body></soapenv:Envelope>
实际内容:
{"returncode":"10006","returnmsg":"未获取到交易机构信息","fpdm":"null","fphm":"null","kprq":"null"}
参考 http://www.iteye.com/problems/73011
$$$$$ 使用dom4j可解析它
public static void main(String[] args) throws Exception {
String retXml = readStringFromFile("d://a.txt","GBK");//你刚得到的返回报文 Document document = DocumentHelper.parseText(retXml); OutputFormat format = OutputFormat.createPrettyPrint();
StringWriter sw = new StringWriter();
XMLWriter xw = new XMLWriter(sw, format);
xw.setEscapeText(false);
xw.write(document);
xw.flush(); String finalRetXml = sw.toString();
System.out.println("最终返回报文:\n"+finalRetXml);
}
最终得到:
文件 d://a.txt存在与否?: true
读到的文件内容如下:
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><validateInvoiceResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><validateInvoiceReturn xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">{"returncode":"10006","returnmsg":"未获取到交易机构信息","fpdm":"null","fphm":"null","kprq":"null"}</validateInvoiceReturn></validateInvoiceResponse></soapenv:Body></soapenv:Envelope>
最终返回报文:
<?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<validateInvoiceResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<validateInvoiceReturn xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="soapenc:string">{"returncode":"10006","returnmsg":"未获取到交易机构信息","fpdm":"null","fphm":"null","kprq":"null"}</validateInvoiceReturn>
</validateInvoiceResponse>
</soapenv:Body>
</soapenv:Envelope>
最新文章
- 电路相关知识--读<;<;继电器是如何成为CPU的>;>;
- inner join on, left join on, right join on的区别与介绍
- LeetCode 6 ZigZag Conversion(规律)
- (C#) 创建单元测试(Unit Test).
- 网络编辑基础:对HTTP协议的头信息详解
- 12. leetcode 455.Assign Cookies
- EMC CX4-480服务器raid磁盘数据恢复案例
- packer的基本使用
- html中layui+jfinal模板实现前端搜索功能
- printf scanf cin cout的区别与特征
- bootstrap table使用及遇到的问题
- Django-基础-2-ORM
- 基础选择器,长度与颜色,标签display,嵌套关系,盒模型,盒模型布局
- linux常见基本命令
- js 迭代 方法
- BZOJ4078 WF2014Metal Processing Plant(二分答案+2-SAT)
- system函数的应用一例
- ARPG游戏打击感相关的技术简单总结
- SQL语句优化 (二) (53)
- 在web.xml中添加servlet报错问题
热门文章
- [dijkstra+heap优化] 模板
- 升级vs工程到vs2010(以上)工程找不到OutputDebugStr报错
- Struts2 Action中的方法命名不要以get开头
- 黑马程序员——JAVA基础之装饰设计模式
- elasticsearch的marvel
- MapReduce 2简介
- Oracle调整联机日志大小
- Windows环境下使用Redis缓存工具的图文详细方法
- Google Tensorflow 源码编译(一):Protobuf<;v3.0.0-alpha-3>;
- Asp.net MVC 之异常处理