soap Xml格式拼接和解析代码总结
程序员文章站
2022-03-20 11:15:56
...
soap格式拼接和解析
import cn.hutool.json.XML;
public class SoapUtils {
/**
* 拼接发送的xml
*
* @param key
* @param params
* @param serviceType
*/
public static String soapCreate(String key,String params,String serviceType){
String soap="<soapenv:Envelope "+"xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" "+
"xmlns:web=\"http://webservice.bjzcyy.cn/\">"+"<soapenv:Header/>"+"<soapenv:Body>"+"<web:ERPInterface>"
+"<Key>"+key+"</Key>"+"<Params>"+params+"</Params>"+"<serviceType>"+serviceType+"</serviceType>"
+"</web:ERPInterface>"+"</soapenv:Body>"+"</soapenv:Envelope>";
return soap;
}
/**
* 解析soap得到flag
* @param soapResponse
*/
public static String getFlagBySoap(String soapResponse){
cn.hutool.json.JSONObject xmlJSONObj = XML.toJSONObject(soapResponse);
String s=xmlJSONObj.getJSONObject("soap:Envelope").getJSONObject("soap:Body").getJSONObject("ns2:ERPInterfaceResponse")
.getJSONObject("return").get("flag").toString();
return s;
}
}