gpt4 book ai didi

soap - Groovy - 解析 SOAP 响应 XML 以获取数据

转载 作者:行者123 更新时间:2023-12-01 08:33:03 24 4
gpt4 key购买 nike

我有以下文本值。我需要解析 XML 并获取每个 XML 的值。请建议如何在 Groovy 中进行操作

<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>
<ns0:GetListBy_QualificationResponse xmlns:ns0="urn:WS_CTM_People_ICEVA">
<ns0:getListValues>
<ns0:Person_ID>PPL000000301739</ns0:Person_ID>
<ns0:Submitter>soehler</ns0:Submitter>
<ns0:Profile_Status>Enabled</ns0:Profile_Status>
<ns0:Locale2>en_US</ns0:Locale2>
<ns0:VIP>No</ns0:VIP>
<ns0:Client_Sensitivity>Standard</ns0:Client_Sensitivity>
</ns0:getListValues>
</ns0:GetListBy_QualificationResponse>
</soapenv:Body>
</soapenv:Envelope>

最佳答案

假设您的 xml 位于变量 xml 中的字符串中,那么您可以执行以下操作:

def mapOfValues = new XmlSlurper().parseText(xml)
.Body
.GetListBy_QualificationResponse
.getListValues.children().collectEntries {
[it.name(), it.text()]
}

这使得 mapOfValues 等于包含以下内容的 Map:

[
'Person_ID':'PPL000000301739',
'Submitter':'soehler',
'Profile_Status':'Enabled',
'Locale2':'en_US',
'VIP':'No',
'Client_Sensitivity':'Standard'
]

关于soap - Groovy - 解析 SOAP 响应 XML 以获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39526932/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com