Question

Iam new to groovy ,so as a part of my task i need to update xml .

My xml is ::

<?xml version="1.0" encoding="utf-8"?>
<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>
<root xmlns="">
<queries>


<query list="true" type="Query">
<retrieve extent="3" offset="0" size="10000" subtype="uk.co.netdev.icr.provisioning.data.Corp">
<criteria list="true" type="Criteria">
<string-criteria expression="IAS" field-name="name"/>
</criteria></retrieve></query>
</queries></root></in0></soapenv:Body></soapenv:Envelope>

From this xml i need to remove somepart of xml and should print output as ::

<root xmlns=""><queries><query list="true" type="Query"><retrieve extent="3" offset="0" size="10000" subtype="uk.co.netdev.icr.provisioning.data.Corp"><criteria list="true" type="Criteria"><string-criteria expression="IAS" field-name="name"/></criteria></retrieve></query></queries></root>

please suggest, Thanks.

Was it helpful?

Solution

I guess this is what you need:

def soapMsg = new XmlSlurper().parseText(inputXml);
def output = groovy.xml.XmlUtil.serialize(soapMsg.Body.root)

BTW, your input XML above has some extra tag: "</in0>"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top