I have string like Color=Blue|Size=M|Style=simpleStyle
and it need to be converted as like below by using groovy.
<Item>
<comp>
<name>Color</name>
<value>Blue</value>
</comp>
<comp>
<name>Size</name>
<value>M</value>
</comp>
<comp>
<name>Style</name>
<value>simpleStyle</value>
</comp>
</Item>
I have written groovy for loop something like below. I believe i am trying it in bit harder way. Is there any simple way to produce above XML using Groovy ?
for (int i = 0; StrRelationshipDetails.toString().contains('|'); i++) {
println StrRelationshipDetails.toString()
def StrPair = new StringBuilder(StrRelationshipDetails.substring(0, StrRelationshipDetails.indexOf('|')))
def StrName = new StringBuilder(StrPair.substring(0, StrPair.indexOf('=')))
def StrValue = new StringBuilder(StrPair.substring(StrPair.indexOf('=')+1, StrPair.size()))
StrRelationshipDetails = StrRelationshipDetails.substring(StrRelationshipDetails.indexOf('|')+1, StrRelationshipDetails.size())
}
println StrRelationshipDetails.toString()