2017-10-05 78 views
-1

我已經來響應這樣的 -轉換XML響應有效載荷

<rsp stat="ok" version="1.0"> 
    <result> 
     <tagObject> 
     <id>xx</id> 
     <tag_id>001</tag_id> 
     <type>Test</type> 
     <object_id>101</object_id> 
     <created_at>2013-10-09 11:41:45</created_at> 
     </tagObject> 
     <tagObject> 
     <id>xy</id> 
     <tag_id>002</tag_id> 
     <type>Test</type> 
     <object_id>102</object_id> 
     <created_at>2013-10-09 11:41:45</created_at> 
     </tagObject> 
     <tagObject> 
     <id>xz</id> 
     <tag_id>003</tag_id> 
     <type>Test</type> 
     <object_id>103</object_id> 
     <created_at>2013-10-09 11:43:44</created_at> 
     </tagObject> 
    </result> 
</rsp> 

現在我必須建立一個有效載荷出來,這樣我可以只插入<tag_id><object_id>到數據庫表。

對此有何建議?我正在嘗試使用Xpath3與Dataweave一起工作,但它對我無效。

+0

您可以添加用於dataweave或XPATH3的代碼片段嗎? – AnupamBhusari

回答

0

enter image description here可以使用XML轉換成Java地圖dataweave


%dw 1.0 
%output application/java 
--- 
payload.rsp.result.*tagObject map ((tagObject , indexOfTagObject) -> { 
    tag_id: tagObject.tag_id as :string, 
    object_id: tagObject.object_id as :string 
}) 

停止放:[{TAG_ID = 001,的object_id = 101},{TAG_ID = 002,的object_id = 102} ,{tag_id = 003,object_id = 103}]。