首页 > Web开发 > 详细

webServer_soap——xml解析

时间:2020-07-02 16:10:03      阅读:67      评论:0      收藏:0      [点我收藏+]
 /*获取信息*/
    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;
    }

 

webServer_soap——xml解析

原文:https://www.cnblogs.com/kkxwze/p/13225008.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!