如何将 Xml 数组的值映射到 csv 字段
how to map a value of Xml array to csv field
<?xml version="1.0"?>
<tXML>
<Header>
<Source>1</Source>
<Action_Type>Update</Action_Type>
<Sequence_Number>0</Sequence_Number>
<Batch_ID>4</Batch_ID>
<Reference_ID>043</Reference_ID>
<User_ID>S</User_ID>
<Password>password</Password>
<Message_Type></Message_Type>
<Company_ID>J1</Company_ID>
<Msg_Locale>English (United States)</Msg_Locale>
<Msg_Time_Zone>Eastern Standard Time</Msg_Time_Zone>
<Version></Version>
<Internal_Reference_ID></Internal_Reference_ID>
<Internal_Date_Time_Stamp></Internal_Date_Time_Stamp>
<External_Reference_ID></External_Reference_ID>
<External_Date_Time_Stamp></External_Date_Time_Stamp>
</Header>
<Message>
<DistributionOrder>
<LineItem>
<DoLineNbr>1</DoLineNbr>
<ItemName>135465</ItemName>
<Description>A</Description>
<UpdateActionType></UpdateActionType>
<PackageType></PackageType>
<DoLineStatus>Released</DoLineStatus>
<InventoryAttributes>
<InventoryType>F</InventoryType>
<ProductStatus></ProductStatus>
<BatchNbr></BatchNbr>
<CountryOfOrigin></CountryOfOrigin>
<ItemAttribute1>R</ItemAttribute1>
<ItemAttribute2></ItemAttribute2>
<ItemAttribute3></ItemAttribute3>
<ItemAttribute4></ItemAttribute4>
<ItemAttribute5></ItemAttribute5>
</InventoryAttributes>
<Comment>
<NoteType>MB</NoteType>
<NoteCode>20</NoteCode>
<CommentText>[JPY_ _Mens_ _ _ _ _ _ _ _ _ _ _ ]</CommentText>
<Visibility>0</Visibility>
</Comment>
<Comment>
<NoteType>MB</NoteType>
<NoteCode>13</NoteCode>
<CommentText>[ _00016000.00000_.00000_.00000_ _ _ _ _ _ _ _ ]</CommentText>
<Visibility>0</Visibility>
</Comment>
<Comment>
<NoteType>SC</NoteType>
<NoteCode>02</NoteCode>
<CommentText>[ _ _ _ _R]</CommentText>
<Visibility>0</Visibility>
</Comment>
</LineItem>
<LineItem>
<DoLineNbr>2</DoLineNbr>
<ItemName>4550155140404</ItemName>
<Description>AS LAMBSWOOL VNECK</Description>
<UpdateActionType></UpdateActionType>
<PackageType></PackageType>
<DoLineStatus>Released</DoLineStatus>
<InventoryAttributes>
<InventoryType>F</InventoryType>
<ProductStatus></ProductStatus>
<BatchNbr></BatchNbr>
<CountryOfOrigin></CountryOfOrigin>
<ItemAttribute1>R</ItemAttribute1>
<ItemAttribute2></ItemAttribute2>
<ItemAttribute3></ItemAttribute3>
<ItemAttribute4></ItemAttribute4>
<ItemAttribute5></ItemAttribute5>
</InventoryAttributes>
<Comment>
<NoteType>MB</NoteType>
<NoteCode>20</NoteCode>
<CommentText>[JPY_ _Mens_ _ _ _ _ _ _ _ _ _ _ ]</CommentText>
<Visibility>0</Visibility>
</Comment>
<Comment>
<NoteType>MB</NoteType>
<NoteCode>13</NoteCode>
<CommentText>[ _00016000.00000_.00000_.00000_ _ _ _ _ _ _ _ ]</CommentText>
<Visibility>0</Visibility>
</Comment>
<Comment>
<NoteType>SC</NoteType>
<NoteCode>02</NoteCode>
<CommentText>[ _ _ _ _R]</CommentText>
<Visibility>0</Visibility>
</Comment>
</LineItem>
</DistributionOrder>
</Message>
</tXML>
我在 XMl 上方映射到 CSV 管道去限制格式,需要有关如何循环 LineItem-Comment 并检查 NoteType 和 NoteCode 以及打印 CommentText 值的帮助。
这是我的条件
Loop Over /tXML/Message/DistributionOrder/LineItem/Comment
If
/tXML/Message/DistributionOrder/LineItem/Comment/NoteType = SC and /tXML/Message/DistributionOrder/LineItem/Comment/NoteCode = 02
Then
Remove start and end index of /tXML/Message/DistributionOrder/LineItem/Comment/CommentText
我的 csv 数据编织看起来像这样
%dw 2.0
output application/csv header = false , separator = "|" , quoteValues = false
---
payload.tXML.Message.DistributionOrder.*LineItem map ((LineItem , indexofLineItem) -> {
column_1: "000000002",
column_2: (payload.tXML.Message.DistributionOrder.ProcessInfo.RefTextField8 splitBy "_")[0] replace "[" with "",
column_3: if(payload.tXML.Message.DistributionOrder.ProcessInfo.RefNumberField1 != null) (payload.tXML.Message.DistributionOrder.ProcessInfo.RefNumberField1) else "00000000",
column_4:"",
column_5:"",
column_6: "",
column_7: "",
column_8: "",
.
.
.
.
.
.
coulmn_56: ?(
If
/tXML/Message/DistributionOrder/LineItem/Comment/NoteType = SC and /tXML/Message/DistributionOrder/LineItem/Comment/NoteCode = 02
Then
Remove start and end index of /tXML/Message/DistributionOrder/LineItem/Comment/CommentText)
})
我需要 column_56 的映射。
这是为您提供评论文本的映射,我不确定您要的是什么。
%dw 2.0
output application/csv header = false , separator = "|" , quoteValues = false
---
payload.tXML.Message.DistributionOrder.*LineItem map ((LineItem , indexofLineItem) -> {
column_1: "000000002",
column_56: (LineItem.*Comment[?($.NoteType == 'SC' and $.NoteCode == '02')][0].CommentText) replace "[" with "" replace "]" with ""
})
<?xml version="1.0"?>
<tXML>
<Header>
<Source>1</Source>
<Action_Type>Update</Action_Type>
<Sequence_Number>0</Sequence_Number>
<Batch_ID>4</Batch_ID>
<Reference_ID>043</Reference_ID>
<User_ID>S</User_ID>
<Password>password</Password>
<Message_Type></Message_Type>
<Company_ID>J1</Company_ID>
<Msg_Locale>English (United States)</Msg_Locale>
<Msg_Time_Zone>Eastern Standard Time</Msg_Time_Zone>
<Version></Version>
<Internal_Reference_ID></Internal_Reference_ID>
<Internal_Date_Time_Stamp></Internal_Date_Time_Stamp>
<External_Reference_ID></External_Reference_ID>
<External_Date_Time_Stamp></External_Date_Time_Stamp>
</Header>
<Message>
<DistributionOrder>
<LineItem>
<DoLineNbr>1</DoLineNbr>
<ItemName>135465</ItemName>
<Description>A</Description>
<UpdateActionType></UpdateActionType>
<PackageType></PackageType>
<DoLineStatus>Released</DoLineStatus>
<InventoryAttributes>
<InventoryType>F</InventoryType>
<ProductStatus></ProductStatus>
<BatchNbr></BatchNbr>
<CountryOfOrigin></CountryOfOrigin>
<ItemAttribute1>R</ItemAttribute1>
<ItemAttribute2></ItemAttribute2>
<ItemAttribute3></ItemAttribute3>
<ItemAttribute4></ItemAttribute4>
<ItemAttribute5></ItemAttribute5>
</InventoryAttributes>
<Comment>
<NoteType>MB</NoteType>
<NoteCode>20</NoteCode>
<CommentText>[JPY_ _Mens_ _ _ _ _ _ _ _ _ _ _ ]</CommentText>
<Visibility>0</Visibility>
</Comment>
<Comment>
<NoteType>MB</NoteType>
<NoteCode>13</NoteCode>
<CommentText>[ _00016000.00000_.00000_.00000_ _ _ _ _ _ _ _ ]</CommentText>
<Visibility>0</Visibility>
</Comment>
<Comment>
<NoteType>SC</NoteType>
<NoteCode>02</NoteCode>
<CommentText>[ _ _ _ _R]</CommentText>
<Visibility>0</Visibility>
</Comment>
</LineItem>
<LineItem>
<DoLineNbr>2</DoLineNbr>
<ItemName>4550155140404</ItemName>
<Description>AS LAMBSWOOL VNECK</Description>
<UpdateActionType></UpdateActionType>
<PackageType></PackageType>
<DoLineStatus>Released</DoLineStatus>
<InventoryAttributes>
<InventoryType>F</InventoryType>
<ProductStatus></ProductStatus>
<BatchNbr></BatchNbr>
<CountryOfOrigin></CountryOfOrigin>
<ItemAttribute1>R</ItemAttribute1>
<ItemAttribute2></ItemAttribute2>
<ItemAttribute3></ItemAttribute3>
<ItemAttribute4></ItemAttribute4>
<ItemAttribute5></ItemAttribute5>
</InventoryAttributes>
<Comment>
<NoteType>MB</NoteType>
<NoteCode>20</NoteCode>
<CommentText>[JPY_ _Mens_ _ _ _ _ _ _ _ _ _ _ ]</CommentText>
<Visibility>0</Visibility>
</Comment>
<Comment>
<NoteType>MB</NoteType>
<NoteCode>13</NoteCode>
<CommentText>[ _00016000.00000_.00000_.00000_ _ _ _ _ _ _ _ ]</CommentText>
<Visibility>0</Visibility>
</Comment>
<Comment>
<NoteType>SC</NoteType>
<NoteCode>02</NoteCode>
<CommentText>[ _ _ _ _R]</CommentText>
<Visibility>0</Visibility>
</Comment>
</LineItem>
</DistributionOrder>
</Message>
</tXML>
我在 XMl 上方映射到 CSV 管道去限制格式,需要有关如何循环 LineItem-Comment 并检查 NoteType 和 NoteCode 以及打印 CommentText 值的帮助。
这是我的条件
Loop Over /tXML/Message/DistributionOrder/LineItem/Comment
If
/tXML/Message/DistributionOrder/LineItem/Comment/NoteType = SC and /tXML/Message/DistributionOrder/LineItem/Comment/NoteCode = 02
Then
Remove start and end index of /tXML/Message/DistributionOrder/LineItem/Comment/CommentText
我的 csv 数据编织看起来像这样
%dw 2.0
output application/csv header = false , separator = "|" , quoteValues = false
---
payload.tXML.Message.DistributionOrder.*LineItem map ((LineItem , indexofLineItem) -> {
column_1: "000000002",
column_2: (payload.tXML.Message.DistributionOrder.ProcessInfo.RefTextField8 splitBy "_")[0] replace "[" with "",
column_3: if(payload.tXML.Message.DistributionOrder.ProcessInfo.RefNumberField1 != null) (payload.tXML.Message.DistributionOrder.ProcessInfo.RefNumberField1) else "00000000",
column_4:"",
column_5:"",
column_6: "",
column_7: "",
column_8: "",
.
.
.
.
.
.
coulmn_56: ?(
If
/tXML/Message/DistributionOrder/LineItem/Comment/NoteType = SC and /tXML/Message/DistributionOrder/LineItem/Comment/NoteCode = 02
Then
Remove start and end index of /tXML/Message/DistributionOrder/LineItem/Comment/CommentText)
})
我需要 column_56 的映射。
这是为您提供评论文本的映射,我不确定您要的是什么。
%dw 2.0
output application/csv header = false , separator = "|" , quoteValues = false
---
payload.tXML.Message.DistributionOrder.*LineItem map ((LineItem , indexofLineItem) -> {
column_1: "000000002",
column_56: (LineItem.*Comment[?($.NoteType == 'SC' and $.NoteCode == '02')][0].CommentText) replace "[" with "" replace "]" with ""
})