$使用dom4j可解析 返回&#x等字样的 html转义字符【转】
如果以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>
随机推荐
- [转载] 虚拟机下面安装windows+oracle ASM的过程
转帖:https://www.2cto.com/database/201303/195261.html 最开始的时候 我找了一个挺好的教程 安装过 但是已经找不到了,先转载一下这个内容,后续再测试完善 ...
- JetBrains全系列破解
教程开始: 进入自己安装idea路径的bin目录下,将刚刚下载好的JetbrainsCrack.jar复制到此目录下: 还是在bin目录下,找到idea.exe.vmoptions和idea64.ex ...
- Delphi导出数据的多种方法
//Dxdbgrid,则直接用SaveToexcel即可//使用 ExcelWithOdbc 控件function TDataModule1.GetDataToFile(DsData: TObject ...
- 简单谈谈DNS协议
DNS协议也可以称为DNS服务,全称是Domain Name System,即域名系统,和HTTP协议一样,也是一个位于应用层的协议(服务),它是基于运输层的UDP协议的,关于网络协议的分层介绍,见这 ...
- BZOJ3569 DZY Loves Chinese II(随机化+树上差分+线性基)
上一题的强制在线版.对图跑出一个dfs树,给非树边赋上随机权值,树边的权值为覆盖他的非树边权值的异或.这样如果某条树边和覆盖他的非树边都被割掉(即图不连通),他们的异或值就为0.每次对询问看有没有子集 ...
- POJ3252-RoundNumbers-排列组合
当一个数的二进制表示中,0的个数大于或等于1的个数时,叫做RoundNumber.求从S到F两个数(包含)之间的RoundNumber个数. 这类题一般都是先求出0到N的个数,然后两个相减. 由于题目 ...
- BZOJ5297 [CQOI2018] 交互网络 【MatrixTree定理】
题目分析: 这题是一道板题,属于MatrixTree定理的简单拓展,邻接矩阵与有向图邻接矩阵一致,度数矩阵作为入度矩阵.然后高斯消元即可. 代码: #include<bits/stdc++.h& ...
- 解决操作WordPress时提示输入FTP信息
WordPress安装个插件,提示输入FTP信息. 出现这个的问题就是Nginx的执行身份非文件属主身份. 解决方法: 假设你的wordpress安装目录为/data/wwwroot/default/ ...
- 小强学Python+OpenCV之-1.3绘图
目标 今天的课程比较轻松,我们来学习一下OpenCV中几个绘图函数: cv2.line cv2.rectangle cv2.circle 画直线 直接经过前面两节的内容.我想直接上代码应该是可以接受的 ...
- Python基础之控制流
介绍一些Python的基本的东西,你会发现,Python真的很简单.我也尽可能说得简单一些,因为我理解的也很简单. 在到目前为止我们所见到的程序中,总是有一系列的语句,Python忠实地按照它们的顺序 ...