2016-09-16 1 views
1

아래 텍스트의 값을 텍스트로 사용하고 있습니다. XML을 파싱하고 각 XML에 대한 가치를 얻어야합니다. 당신의 XML 변수 xml의 String에, 당신은 할 수있다 가정하면 그루비Groovy - SOAP 응답 XML을 구문 분석하여 데이터를 가져옵니다.

<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> 

답변

2

에서 수행하는 방법을 제안하십시오 :

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

이 포함 된지도와 같은 mapOfValues :

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