拆分XML消息并基于Mule esb中的某些条件进行汇总 [英] splitting an xml message and aggregating based on some condition in mule esb
问题描述
我的inputXML:
My inputXML:
<Orders>
<Order><OrderId>1</OrderId><Total>10</Total></Order>
<Order><OrderId>2</OrderId><Total>20</Total></Order>
<Order><OrderId>3</OrderId><Total>30</Total></Order>
<Order><OrderId>4</OrderId><Total>40</Total></Order>
<Order><OrderId>5</OrderId><Total>50</Total></Order>
<Order><OrderId>5</OrderId><Total>60</Total></Order>
<Order><OrderId>5</OrderId><Total>70</Total></Order>
<Order><OrderId>5</OrderId><Total>80</Total></Order>
<Order><OrderId>5</OrderId><Total>90</Total></Order>
</Orders>
我需要从文件中读取此输入XML.并需要根据以下条件将其写入不同的文件
I need to read this input XML from a File. And need to write this to Different files based on the following conditions
/Orders/Order/Total==10 then write this record to file1.
/Orders/Order/Total>10 and /Orders/Order/Total<=40 then write the records to file2.
/Orders/Order/Total>40 then write the records to file3.
我的文件1 o/p(预期):
my file 1 o/p(expected):
<OrderId>1</OrderId><Total>10</Total>
我的文件2 o/p(预期):
my file 2 o/p(expected):
<OrderId>2</OrderId><Total>20</Total>
<OrderId>3</OrderId><Total>30</Total>
<OrderId>4</OrderId><Total>40</Total>
我的文件3 o/p(预期):
my file 3 o/p(expected):
<OrderId>5</OrderId><Total>50</Total>
<OrderId>6</OrderId><Total>60</Total>
<OrderId>7</OrderId><Total>70</Total>
.
.
.
我对Mule ESB有点陌生.我对m子的转换和转换感到困惑.
I am bit new to Mule ESB. I am confused with transformations and conversions of mule.
有人可以建议在我的m子流中使用的最佳拆分和聚合策略以及组件.还要在组件中使用的配置.
can some one suggest the best splitting and aggregating strategy and components to be used in my mule flow.Also the configuration to be used in components..
请注意,这是示例输入XML.我实时需要处理大型XML文件.因此,建议最好的解决方案.预先感谢!
推荐答案
使用for each
组件并迭代到每个Order元素.提示:使用xpath.例如,将其放在收集字段#[xpath3('//*:Orders//*:Order', payload, 'NODESET')]
Use for each
component and iterate to each Order element. Tip: use xpath. For example, put this on collection field #[xpath3('//*:Orders//*:Order', payload, 'NODESET')]
在您的for each
内,添加具有这些条件的选择组件.显然,在这里也要使用xpath.例如,当组件#[Integer.parseInt(xpath3('.//Total',payload)) > 40]
Inside your for each
, add a choice component that has those conditions. Obviously, use xpath as well here. For instance, on when component #[Integer.parseInt(xpath3('.//Total',payload)) > 40]
在每个选项的选项上,放置一个DOM to XML
组件以将订单元素设置为有效负载,然后添加Object to String
组件.链上的最后一个是文件写入/附加逻辑,该逻辑可以是Java转换器或表达式组件. (更好的选择是使用StringBuilder,您只需在其中附加每个顺序,然后将3个文件保存在for each
组件之后).
On each choice's option, put a DOM to XML
component to set the order element as payload, then add Object to String
component. Last on the chain will be the file write/append logic which could be java transformer or expression component. (Better alternative is to use a StringBuilder where you just append each order then save the 3 files after the for each
component).
希望您知道Java,所以最后一部分很有意义.
Hope you know Java so the last part make sense.
这篇关于拆分XML消息并基于Mule esb中的某些条件进行汇总的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!