首页 > 技术文章 > webServer_soap——xml解析

kkxwze 2020-07-02 15:28 原文

<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.2.0</version>
</dependency>


/*获取信息*/ public static List<Map<String, Object>> callPlace() throws IOException { OkHttpClient client = new OkHttpClient(); MediaType mediaType = MediaType.parse("application/xml"); RequestBody body = RequestBody.create(mediaType, "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" + " <soap:Body>" + " <ns:call_Place xmlns:ns= \"http://NurseService.xh.com\">" + " </ns:call_Place>" + " </soap:Body>" + "</soap:Envelope>"); Request request = new Request.Builder() .url("http://" + IniUtil.getConfig().get("ipAddress") + "/PSIM_WS_Maternity/services/NurseService/soap") .post(body) .addHeader("Content-Type", "application/xml") .build(); Response response = client.newCall(request).execute(); String s = new String(response.body().bytes(), "utf-8"); System.out.println(s); InputStream is = new ByteArrayInputStream(s.getBytes("utf-8")); SAXReader reader = new SAXReader(); Document document = null;// 生成XML文档 try { document =reader.read(new BufferedReader(new InputStreamReader(is, "utf-8"))); } catch (DocumentException e) { e.printStackTrace(); } /*解析数组*/ String map = document.getRootElement().elements().get(0).elements().get(0).elements().get(0).getText(); JSONObject jsonObject = JSONObject.parseObject(map); String result = jsonObject.getString("result"); List<Map<String, Object>> mapList = new ArrayList<>(); if ("1".equals(result)) { System.out.println(jsonObject.getString("resultInfo")); String data = jsonObject.getString("data"); List list = JSONObject.parseObject(data, List.class); for (Object o : list) { Map<String, Object> item = (Map) o; //System.out.println(item); mapList.add(item); } } return mapList; }

 

 关于wdsl
WSDL元素

WSDL元素基于XML语法描述了与服务进行交互的基本元素:

Type(消息类型):数据类型定义的容器,它使用某种类型系统(如XSD)。

Message(消息):通信数据的抽象类型化定义,它由一个或者多个part组成。

Part:消息参数

Operation(操作):对服务所支持的操作进行抽象描述,WSDL定义了四种操作:

    单向(one-way):端点接受信息;
    请求-响应(request-response):端点接受消息,然后发送相关消息;
    要求-响应(solicit-response):端点发送消息,然后接受相关消息;
    通知(notification):端点发送消息。

Port Type (端口类型):特定端口类型的具体协议和数据格式规范。

Binding:特定端口类型的具体协议和数据格式规范

Port :定义为绑定和网络地址组合的单个端点。

Service:相关端口的集合,包括其关联的接口、操作、消息等。

 

关于wdsl

WSDL元素

WSDL元素基于XML语法描述了与服务进行交互的基本元素:

Type(消息类型):数据类型定义的容器,它使用某种类型系统(如XSD)。

Message(消息):通信数据的抽象类型化定义,它由一个或者多个part组成。

Part:消息参数

Operation(操作):对服务所支持的操作进行抽象描述,WSDL定义了四种操作:

  • 单向(one-way):端点接受信息;
  • 请求-响应(request-response):端点接受消息,然后发送相关消息;
  • 要求-响应(solicit-response):端点发送消息,然后接受相关消息;
  • 通知(notification):端点发送消息。

Port Type (端口类型):特定端口类型的具体协议和数据格式规范。

Binding:特定端口类型的具体协议和数据格式规范

Port :定义为绑定和网络地址组合的单个端点。

Service:相关端口的集合,包括其关联的接口、操作、消息等。

推荐阅读