如果以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("最终返回报文: "+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>