Skip to Content
0
Jul 25 at 07:25 AM

Adding two XML files based on condition using Groovy in CPI

128 Views Last edit Jul 25 at 07:43 AM 6 rev

Is there any way to merge two XML using groovy in CPI based on condition .

Though I can do this using content enricher but it is not a best practice when it comes to bulk load (several thousands of records).

Consider I have two XML files from two request replies

XML1:

</PerPerson>

<PerPerson>

<personIdExternal>1234</personIdExternal>

<dateOfBirth>1953-07-06T00:00:00.000</dateOfBirth>

</PerPerson>

<PerPerson>

<personIdExternal>5678</personIdExternal>

<dateOfBirth>1962-05-27T00:00:00.000</dateOfBirth>

</PerPerson>

</PerPerson>

XML2:

<PerPersonal>

<PerPersonal>

<firstName>QWE</firstName>

<lastName>ASD</lastName>

<personIdExternal>1234</personIdExternal>

</PerPersonal>

<PerPersonal>

<firstName>LKJH</firstName>

<lastName>LPOI</lastName>

<personIdExternal>5678</personIdExternal>

</PerPersonal>

</PerPersonal>

OUTPUT XML: Based on personIdExternal merging should happen

</PerPerson>

<PerPerson>

<personIdExternal>1234</personIdExternal>

<dateOfBirth>1953-07-06T00:00:00.000</dateOfBirth>

</PerPerson>

<PerPersonal>

<firstName>QWE</firstName>

<lastName>ASD</lastName>

<personIdExternal>1234</personIdExternal>

</PerPersonal>

<PerPerson>

<personIdExternal>5678</personIdExternal>

<dateOfBirth>1962-05-27T00:00:00.000</dateOfBirth>

</PerPerson>

<PerPersonal>

<firstName>LKJH</firstName>

<lastName>LPOI</lastName>

<personIdExternal>5678</personIdExternal>

</PerPersonal>

</PerPerson>

Any script idea on this ?

Thanks
Shiva