xml到mule esb中的列表转换使用数据编织组件 [英] xml to List conversion in mule esb using data weave component

查看:287
本文介绍了xml到mule esb中的列表转换使用数据编织组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下xml作为输入

I have the following xml as my input

<Orders>
<Order>
  <sample id="1"></sample>
  <sample id="2"></sample>
  .
  .
  .
  .    
 </Order>
<Order>
  <sample id="1"></sample>
  <sample id="2"></sample>
  .
  .
  .
  .    
 </Order>
<Order>
   <sample id="1"></sample>
   <sample id="2"></sample>
   .
   .
   .
   .    
</Order>
.
.
.
.
</Orders>

我需要将此xml发送到我的流程中的批处理组件。我的批处理应按以下方式接受每个记录

I need to send this xml to the batch component in my flow. My batch should accept each record in the following manner

  Record1:1st Order
  Record2:2nd Order
  Record3:3rd Order
  .
  .
  .
  .

现在请让我知道我需要在我的 DataWeave )组件来实现这种情况。我尝试了多种方式,但没有结果。我试过这几天,累了。请帮助我在这方面!请共享示例代码。

Now please let me know what coding do I need to do in my DataWeave(Transform message) component to acheive this scenario.I tried multiple ways but no result. I am trying this from past few days and got tired. Please help me in this regard!! Please share the sample code.

输出应如下所示:

1) Order  ---- Object
          sample-----Object
              -sampleValue(i.e; value of 'sample' element)
              -sampleidValue(i.e; value of attribute of 'sample')
          sample-----Object
              -sampleValue(i.e; value of 'sample' element)
              -sampleidValue(i.e; value of attribute of 'sample')
            .
            .
            .
            .
2) Order  ---- Object
          sample-----Object
              -sampleValue(i.e; value of 'sample' element)
              -sampleidValue(i.e; value of attribute of 'sample')
          sample-----Object
              -sampleValue(i.e; value of 'sample' element)
              -sampleidValue(i.e; value of attribute of 'sample')
            .
            .
            .
            .



内部批次:



另一个dataweave组件将此集合转换为csv。

Inside Batch:

I do have another dataweave component that transforms this collection to csv.

此dataweave组件的输入是此集合中的每个对象。

The input of this dataweave component is each object from this collection. The data is extracted from this object and written to the CSV file.

问题I面对集合中的每个对象都是结构

The issue I am facing is Each Object in the collection is of structure

 Order  ---- Object
          sample1-----Object
              -sampleValue(i.e; value of 'sample' element)
              -sampleidValue(i.e; value of attribute of 'sample')
          sample2-----Object
              -sampleValue(i.e; value of 'sample' element)
              -sampleidValue(i.e; value of attribute of 'sample')
            .
            .
            .
            .

但是CSV的输出应该是:

But the output of my CSV should be:

        sample1.sampleValue   sample3.sampleValue   .    .       .       .(this is 'Order1' object)
            sample2.sampleValue   sample6.sampleValue   .    .       .       .(this is 'Order2' object)
.
.
.
.

我无法在CSV文件中获得这种输出。 bcz我的'sample'也是一个对象列表。我在 DataMapper和DataWeave 中也尝试过。请帮助我如何提取值。

I am not able to get the output this way in the CSV file. bcz my 'sample' is also a List of Objects. I tried this in both DataMapper and DataWeave also. Please help me out how to extract the values.

推荐答案

高请找到以下数据编织

%dw 1.0
%output application/csv separator=" "
---

payload.Orders.*Order map {
SampleValue1:$.sample.@id,
SampleValue2:$.sample.@id,
SampleValue3:$.sample.@id   
}

以下是X%dw 1.0

The below is the X%dw 1.0

payload.Orders.*Order map {
SampleValue1:$.sample.@id,
SampleValue2:$.sample.@id,
SampleValue3:$.sample.@id   
}

下面是基于在问题中共享的xml使用的xml。

The below is the xml that I have used based on the xml that is shared in the question.

<?xml version="1.0"?>
<Orders>
<Order>
  <sample id="1">test</sample>
</Order>
<Order>
  <sample id="1">test</sample>
</Order>
<Order>
   <sample id="1">test</sample>
</Order>
</Orders>

希望这有助于!

这篇关于xml到mule esb中的列表转换使用数据编织组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆