0

我已输入 XML 作为有效负载,我想使用批量模式将 XML 值插入到数据库列中。Mule 文档显示批量插入只能使用集合完成。如果可以通过实现集合来完成,我们如何将 xml 转换为集合,然后进行批量插入而不是耗时的 For-each 循环。

使用的骡版本 - v3.8

让我们在下面取样,

示例 XML 作为有效负载输入,

<notes>
  <note number ="1">
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
    <address>
        <mode = "Email">
        <fulladdress>abc@gmail.com</fulladdress>
    </address>
    <organisation>
        <designation type="contractor">Software engineer</designation>
    </organisation>
  </note>
  <note>
  <note number ="2">
    <to>Smith</to>
    <from>Gerri</from>
    <heading>Hello</heading>
    <body>Hi Smith, nice to meet you.</body>
    <address>
        <mode = "Email">
        <fulladdress>def@gmail.com</fulladdress>
    </address>
    <organisation>
        <designation type="permanent">Software engineer</designation>
    </organisation>
  </note>
</notes>

请回答以下两个问题, 1. 如何将此输入的 XML 转换为集合?2. 如何用问题1创建的集合实现批量插入?

4

1 回答 1

0

假设您使用的是 Mule 3,并且您的有效负载如下所示:

<notes>
  <note>
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
  </note>
  <note>
    <to>Smith</to>
    <from>Gerri</from>
    <heading>Hello</heading>
    <body>Hi Smith, nice to meet you.</body>
  </note>
</notes>

您可以使用 DataWeave 将其转换为代表note如下的 Java 对象集合:

%dw 1.0
%output application/java
---
payload.notes.*note

然后,您可以在转换后进行双层插入。

于 2018-08-25T22:07:33.400 回答