Output some selected parameters of XML response to a log file
I tried to output certain parameters of a XML response (below) to a log file.
The parameters I like to output: CoSID, PIN, iPhoneDevice, etc. Not sure how to do this.
def xmlResponse = tStep.getPropertyValue("Response")
def xml = new XmlSlurper().parseText(xmlResponse)
I tried a few combinations of the following 2 lines with no success.
def MESSAGE2 = xml.Body.ShPullResponse.UserData.RepositoryData.ServiceData.MetaSphereData.Msph_Subscriber_BaseInformation.CoSID.text()
// def MESSAGE2 = xml.Body.ShPullResponse.@COSID.text()
log.info MESSAGE2
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<ns1:ShPullResponse xmlns:ns1="http://www.metaswitch.com/srb/soap/sh">
<ns1:ResultCode>2001</ns1:ResultCode>
<ns1:ExtendedResult>
<ns1:ExtendedResultCode>100</ns1:ExtendedResultCode>
<ns1:ExtendedResultDetail>Request successful</ns1:ExtendedResultDetail>
<ns1:ExtendedSubResults/>
</ns1:ExtendedResult>
<ns1:UserData>
<ud:Sh-Data xmlns:ud="http://www.metaswitch.com/srb/soap/sh/userdata" xmlns:u="http://www.metaswitch.com/sdp/soap/sh/userdata">
<ud:RepositoryData>
<ud:ServiceIndication>Msph_Subscriber_BaseInformation</ud:ServiceIndication>
<ud:SequenceNumber>5385</ud:SequenceNumber>
<ud:ServiceData>
<s:MetaSphereData xmlns:s="http://www.metaswitch.com/sdp/soap/sh/servicedata">
<s:Msph_Subscriber_BaseInformation>
<s:DisplayName>Pierre</s:DisplayName>
<s:CoSID>English_VVM_CoS</s:CoSID>
<s:EmailAddress>3313140097@xplornet.com</s:EmailAddress>
<s:Disabled>False</s:Disabled>
<s:DisabledforMigration>False</s:DisabledforMigration>
<s:PrimaryPhoneNumber>3313140097</s:PrimaryPhoneNumber>
<s:PIN>1234</s:PIN>
<s:PreferredLanguage>eng</s:PreferredLanguage>
<s:BillingNumber>3313140097</s:BillingNumber>
<s:Surname>Pierre</s:Surname>
<s:TimeZone>America/Winnipeg</s:TimeZone>
<s:Groupname>TestiPhoneVVM</s:Groupname>
<s:Device>
<s:PhoneNumber>4313140097</s:PhoneNumber>
<s:AnsweringService>lm</s:AnsweringService>=
<s:iPhoneDevice>True</s:iPhoneDevice>
</s:Device>
<s:Password>$Allan****</s:Password>
<s:VideoMessagingEnabled>True</s:VideoMessagingEnabled>
<s:SelfProvStatus>Not applicable</s:SelfProvStatus>
<s:ClusterName/>
<s:InvariantUID>20210904033825FAB24313140097</s:InvariantUID>
</s:Msph_Subscriber_BaseInformation>
</s:MetaSphereData>
</ud:ServiceData>
</ud:RepositoryData>
</ud:Sh-Data>
</ns1:UserData>
</ns1:ShPullResponse>
</soapenv:Body>
</soapenv:Envelope>
Looks the data fields are unique in this case; so easy to extract with a simple closure.
def getData = { item -> xml.'**'.find{it.name() == item }?.text() } //You may use log.info or assign value instead of print if you want to process that info further. println getData('ResultCode') println getData('ExtendedResultCode') println getData('CoSID') println getData('PIN') println getData('iPhoneDevice')