AnsweredAssumed Answered

how to write a groovy to change XML structure?

Question asked by polyana.f.barbosa on Nov 1, 2017
Latest reply on Nov 3, 2017 by roundviewjoseph

Hi all, please could someone help me? I need to change a XML input using a groovy script, but i cant do that and the way i tried not worked. I think im having problems with JDOM library.

My Input is like this one: 

<?xml version="1.0" encoding="utf-8"?>

<DataReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://simconsultas.com.br/">

     <HasError>false</HasError>

     <ErrorDesc />

     <ErrorCode>0</ErrorCode>

     <Rows>

         <ParseDataRow>

             <Status>0</Status>

             <StatusDesc />

             <Parser />

             <Tipo />

             <Columns>

                 <ParseDataColumn>

                     <Key>name</Key>

                     <Value>joao</Value>

                     <Type>string</Type>

                 </ParseDataColumn>

                 <ParseDataColumn>

                     <Key>age</Key>

                     <Value>15</Value>

                     <Type>string</Type>

                 </ParseDataColumn>

                 <ParseDataColumn>

                     <Key>Document</Key>

                     <Value>12345678</Value>

                     <Type>string</Type>

                 </ParseDataColumn>

 </Columns>

 </ParseDataRow>

 </Rows>

</DataReturn>

 

 

And i need to change for:

<?xml version="1.0" encoding="utf-8"?>

<DataReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://simconsultas.com.br/">

     <Rows>

         <Name>joao</Name>

         <age>15</age>

        <Document>12345678</Document>

    </Rows>

</DataReturn>                         

 

Where the name of the output XML element is the key value of the input xml... and i can have N different fields in a different order.  Please, could you help me? How can i do that?

Outcomes