将xml响应转换为有效负载

时间:2017-10-05 10:36:58

标签: mule dataweave xpath-3.0

我的反应是这样的 -

<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,但它对我不起作用。

1 个答案:

答案 0 :(得分:0)

enter image description here您可以使用dataweave将Xml转换为Java地图

%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}]。