Skip to Content
1
Jun 04, 2020 at 12:32 PM

CPI : Groovy script to remove messages tags from the message

2082 Views

Hi Experts,

I am fetching the data from the SELECT datastore and have to map it to OData structure. To generate the xsd, I have to from the message tag <message id="1"> where the number=1 is dynamic.

I tried with replaceAll. But could not remove the entire tag as it is dynamic.

Looking for a groovy script to remove the above-mentioned tag for the below input structure:

<?xml version='1.0' encoding='UTF-8'?>
<messages>
    <message id="0">
<contentoffirstmessage>
    </message>
    <message id="1">
<contentofsecondmessage>
    </message>
    <message id="2">
<contentofthirdmessage>
    </message>
    <message id="3">
<contentoffourthmessage>
    </message>
......
    <message id="n">
<contentofnthmessage>
    </message>
</messages>

Expected Output:

<?xml version='1.0' encoding='UTF-8'?>
<messages>
<contentoffirstmessage>
<contentofsecondmessage>
<contentofthirdmessage>
<contentoffourthmessage>
......
<contentofnthmessage>
</messages>

Regards,

Pavan G