Skip to Content
0
Dec 15, 2022 at 08:29 AM

Groovy help for replacing a string

758 Views Last edit Dec 15, 2022 at 08:30 AM 2 rev

Hi Experts,

I need to replace ns3:Product xmlns:ns3="http://xc.Oracle.com" with ns3:Product but while running the below script getting error at LIne - 6 . Please suggest .

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
   
       def body = message.getBody(String) as String;
       body = body.replaceAll("<ns3:Product xmlns:ns3="http://xc.Oracle.com">","<ns3:Product>");
       message.setBody(body);
       return message;
}<br>

Input

<?xml version="1.0" encoding="UTF-8"?>
<ns3:ProductMaster xmlns:ns3="http://xc.Oracle.com">
<ns3:ProductMasterRequest>
<ns3:Token></ns3:Token>
<ns3:ProductL>
<ns3:Product xmlns:ns3="http://xc.Oracle.com">
<ns3:Code>675</ns3:Code>
<ns3:ItemCode>CR-CMMD</ns3:ItemCode>
<ns3:ItemType>1</ns3:ItemType>
<ns3:ItemDescription>BLUE</ns3:ItemDescription>
</ns3:Product>
</ns3:ProductL>
</ns3:ProductMasterRequest>
</ns3:ProductMaster><br>