I have a loop below to create an array of variables on my XML. The issue is that for the first time it is running, it is including all my rows at the first occurrence in my output array.
Any comments are welcome.
Many thanks!
pqpwp*.appendNode('PostalAcc', values[0])
pqpwp*.appendNode('CloseAmt', values[1])
pqpwp*.appendNode('Rates',)
def rates = ltrData.PqPwp.Rates
def values = ["Under 0 0.10% 0.08% 0.10%","Under 1 0.10% 0.08% 0.10%","Under 2 0.10% 0.08% 0.10%","Under 3 0.10% 0.08% 0.10%"]
for (int i = 2; i<10; i++)
{
if (values[i])
{
rates*.appendNode('Rate',)
def rate = ltrData.PqPwp.Rates.Rate
rate*.appendNode('Column1', values[i].substring(0,14))
rate*.appendNode('Column2', values[i].substring(15,23))
rate*.appendNode('Column3', values[i].substring(24,31))
rate*.appendNode('Column4', values[i].substring(32,42))
}
}
actual xml output
<ltrData>
<PqPwp>
<PostalAcc>910060121</PostalAcc>
<CloseAmt>514.17</CloseAmt>
<Rates>
<Rate>
<Column1>Under ?1 2</Column1>
<Column2> 0.10%</Column2>
<Column3> 0.08%</Column3>
<Column4> 0.10%</Column4>
<Column1>?1 plus 3</Column1>
<Column2> 1.39%</Column2>
<Column3> 1.11%</Column3>
<Column4> 1.40%</Column4>
</Rate>
<Rate>
<Column1>?1 plus 3</Column1>
<Column2> 1.39%</Column2>
<Column3> 1.11%</Column3>
<Column4> 1.40%</Column4>
</Rate>
</Rates>
xml output desired
<ltrData>
<PqPwp>
<PostalAcc>910060121</PostalAcc>
<CloseAmt>514.17</CloseAmt>
<Rates>
<Rate>
<Column1>Under ?1 2</Column1>
<Column2> 0.10%</Column2>
<Column3> 0.08%</Column3>
<Column4> 0.10%</Column4>
</Rate>
<Rate>
<Column1>?1 plus 3</Column1>
<Column2> 1.39%</Column2>
<Column3> 1.11%</Column3>
<Column4> 1.40%</Column4>
</Rate>
</Rates>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…