Edited... My knowledge in Groovy is basic and I need to perform the following action which I have no idea how to do.
let's say I have this XML:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:analyzeEffectOfReplaceOfferResponse>
<ns2:productOfferings>
<ns2:productOffering xsi:type="ns2:ProductOfferingInstanceCore" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ns2:opExtn>C_P87531945-0993-46d1-8f23-ed23caa6e0cf</ns2:opExtn>
<ns2:productOffering>
<ns9:id>8447669</ns9:id>
</ns2:productOffering>
<ns2:productOffering>
<ns9:id>8447100</ns9:id>
</ns2:productOffering>
</ns2:productOffering>
</ns2:productOfferings>
</ns2:analyzeEffectOfReplaceOfferResponse>
</soap:Body>
</soap:Envelope>
given an XPath expression like:
/Body/analyzeEffectOfReplaceOfferResponse/productOfferings/productOffering/productOffering
and GPathResult as:
gpathRequest = new XmlSlurper().parse(inputFile)
I know how to use findAll to search for all related tags. Let's say I stored the Xpath in a xPath variable:
def gpath = "XML." + xPaths
child = Eval.me( 'XML', gpathRequest, gpath ).depthFirst().findAll{it.value}
However I am not sure how to handle the result here in form of collection. How can I add a new property after finding the result I need?