Forum Discussion

Jasper175's avatar
Jasper175
Frequent Contributor
12 years ago

XmlParser - finding a child value &returning a parent value

I searched through all the XmlSlurper codes and not helping in my case. I have a return of devices that each MAC Address has two ports and various child values, one of which is the phoneNumber (did).
However I only have the phoneNumber (did) to search with and want to pull the macAddress that it belongs to.

Here is a sample of an XML testStep in SoapUI

    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<ns2:GetDeviceServiceDidMapResponse xmlns:ns2="http://xyz" xmlns:ns3="http://xyz" xmlns:ns4="http://xyz">
<ns2:deviceUnits>
<ns2:macAddress>FFFFFFF202B2</ns2:macAddress>
<ns2:deviceTypeId>770</ns2:deviceTypeId>
<ns2:numberOfPorts>2</ns2:numberOfPorts>
<ns2:devicePorts>
<ns2:portNumber>1</ns2:portNumber>
<ns2:serviceEntities>
<ns2:networkId>16869460</ns2:networkId>
<ns2:didTargets>
<ns2:did>11002003000</ns2:did>
<ns2:didType>PHYS</ns2:didType>
<ns2:startDate>2012-09-25</ns2:startDate>
</ns2:didTargets>
<ns2:startDate>2012-09-25</ns2:startDate>
</ns2:serviceEntities>
</ns2:devicePorts>
</ns2:deviceUnits>
<ns2:deviceUnits>
<ns2:macAddress>ABCDEF123456</ns2:macAddress>
<ns2:deviceTypeId>701</ns2:deviceTypeId>
<ns2:numberOfPorts>2</ns2:numberOfPorts>
<ns2:devicePorts>
<ns2:portNumber>2</ns2:portNumber>
<ns2:serviceEntities>
<ns2:networkId>16869466</ns2:networkId>
<ns2:didTargets>
<ns2:did>12003004000</ns2:did>
<ns2:didType>PHYS</ns2:didType>
<ns2:startDate>2012-09-25</ns2:startDate>
</ns2:didTargets>
<ns2:startDate>2012-09-25</ns2:startDate>
</ns2:serviceEntities>
</ns2:devicePorts>
<ns2:devicePorts>
<ns2:portNumber>1</ns2:portNumber>
<ns2:serviceEntities>
<ns2:networkId>16869467</ns2:networkId>
<ns2:didTargets>
<ns2:did>12003004001</ns2:did>
<ns2:didType>PHYS</ns2:didType>
<ns2:startDate>2012-09-25</ns2:startDate>
</ns2:didTargets>
<ns2:startDate>2012-09-25</ns2:startDate>
</ns2:serviceEntities>
</ns2:devicePorts>
</ns2:deviceUnits>
</ns2:GetDeviceServiceDidMapResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>



In here I want to FIND the phoneNumber (did) 12003004001 and report back the macAddress it is set to ABCDEF123456.

So far my code is:

    def response = context.expand( '${getDeviceServiceDidMap#Response}' )

def xml = new XmlSlurper().parseText(response).Body.GetDeviceServiceDidMapResponse.deviceUnits.devicePorts.serviceEntities.didTargets.find
{it.did == "12003004001"}.???????.text()


The ? part is where I'm not sure what I'm doing - I tried setting the path to the macAddress but nothing is working.

Thank you,
Rob
No RepliesBe the first to reply