on ‎2022 Dec 15 8:29 AM
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>
Request clarification before answering.
Hi Arvik
When you have a double quote inside a string, that is delimited by double quotes, it confuses things. Instead, you need to quote them like this:
body = body.replaceAll("<ns3:Product xmlns:ns3=\"http://xc.Oracle.com\">","<ns3:Product>");Notice the two backslashes inside the string.
Regards,
Morten
P.S. You don't need a semicolon at the end of a statement in Groovy.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 15 | |
| 9 | |
| 6 | |
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.