2016-07-19 52 views
0

打印這是DB

我的ResultSet
{result={name=Sanjay,address=india,phone=xxxxxxxxxx},  {name=Amit,address=india,phone=xxxxxxxxxx}} 

我想如下格式(XML格式)的幫助下變換在mule-

<?xml version="1.0" encoding="UTF-8"?> 
<resultset> 
<lines> 
    <line1> 
    <name>Sanjay</name> 
    <address>india</address> 
    <phone>xxxxxxxxxx</phone> 
    </line1> 
    <line2> 
    <name>Amit</name> 
    <address>india</address> 
    <phone>xxxxxxxxxx</phone> 
    </line2> 
</lines> 
</resultset> 

變換消息我所做的變換消息,就像是:

{ 
resultset: { 
lines :{(payload.result map 
"line$$" :{ 
name:$.name, 
address:$.address, 
phone:$.phone 
} 

)} 
} 
} 

對於這件T我得到的轉換

<resultset> 
<lines> 
    <line0> 
    <name>Sanjay</name> 
    <address>india</address> 
    <phone>xxxxxxxxxx</phone> 
    </line0> 
    <line1> 
    <name>Amit</name> 
    <address>india</address> 
    <phone>xxxxxxxxxx</phone> 
    </line1> 
</lines> 

如何解決這個問題? 由於提前

回答

0

以下似乎工作:

{ 
    resultset: { 
    lines :{(payload.result map using (label = "line" ++ ($$ + 1)) 
     (label) : { 
      name: $.name, 
      address: $.address, 
      phone: $.phone 
     } 
    )} 
    } 
} 

輸出:

<?xml version='1.0' encoding='UTF-8'?> 
<resultset> 
<lines> 
    <line1> 
    <name>Sanjay</name> 
    <address>india</address> 
    <phone>xxxxxxxxx</phone> 
    </line1> 
    <line2> 
    <name>Amit</name> 
    <address>india</address> 
    <phone>xxxxxxxxxx</phone> 
    </line2> 
</lines> 
</resultset> 
+0

謝謝@cooper,正常工作 – Sanjay

0

這種替代也給出了相同的結果裏面的

%dw 1.0 
%output application/xml 
--- 
{ 
    resultset: { 
     lines : { 
      (payload.result map { 
       ("line" ++ ($$ + 1)) : { 
        name: $.name, 
        address: $.address, 
        phone: $.phone 
       } 
      }) 
     } 
    } 
} 

敷線結構大括號map { ... },並填充鑰匙直接("line" ++ ($$ + 1))