Java解析调用webservice服务的返回XML串

本文由Markdown语法编辑器编辑完成。

1. 需求分析;

已知当在调用某一webservice的服务时,如果调用成功,会接受到该服务的返回XML串。后端在获取了该XML原始串时,需要进行解析,将其解析为JSON格式,以便于发送到前台,供前台页面显示和交互。

2. 解决方案:

该XML的原始形式为:

<?xml version="1.0" encoding="UTF-8" ?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <SOAP-ENV:Body>
        <MZHLYYServiceResponse xmlns="http://tempuri.org">
            <MZHLYYServiceResult>
                <![CDATA[<CrossSectionPrescriptionAuditResult><ClientType>c1</ClientType><Prescriptions><Prescription><PrescriptionId>10075449</PrescriptionId><AuditResultCode>1</AuditResultCode></Prescription><Prescription><PrescriptionId>10075450</PrescriptionId><AuditResultCode>2</AuditResultCode></Prescription></Prescriptions></CrossSectionPrescriptionAuditResult>]]>
            </MZHLYYServiceResult>
        </MZHLYYServiceResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我希望能够解析到的核心内容是,对于每一个Prescription, 都有两个属性: PrescriptionId和AuditResultCode。这样在返回的XML中有两个Prescription, 因此返回的应该是一个JSON数组。

[
    {
        "PrescriptionId": 10075449,
        "AuditResultCode": 1
    },
    {
        "PrescriptionId": 10075450,
        "AuditResultCode": 2
    }
]

3. 参考链接:

1.dom4j解析xml字符串实例 https://www.cnblogs.com/macula/archive/2011/07/27/2118003.html
2. 在java中使用dom4j解析xml
https://www.cnblogs.com/nerxious/archive/2013/05/04/3060263.html
3. Extract string between two strings in java
https://stackoverflow.com/questions/16597303/extract-string-between-two-strings-in-java/16597374

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

inter_peng

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值