使用数据编织将日期从 xml 转换为 csv
transforming date from xml to csv using dataweave
我想使用 dataweave 将来自 xml 文件的日期属性转换为 csv 格式。现在,转换规则是 'If date is Sunday, make the date minus 6 days'。否则保持原样。
如果你的输入是这样的-
<?xml version='1.0' encoding='UTF-8'?>
<root>
<createDate>2016-05-08</createDate>
</root>
然后您可以使用下面的数据编织代码来获取所需的日期。当日期是星期天时,从日期中减去 6 天 -
%dw 1.0
%output application/csv
---
{
row: {
date: (payload.root.createDate as :date) unless
(((payload.root.createDate as :date) as :string {format: "E"}) == 'Sun')
otherwise ((payload.root.createDate as :date) - |P6D|)
}
}
它会输出如下 -
date
2016-05-02
我想使用 dataweave 将来自 xml 文件的日期属性转换为 csv 格式。现在,转换规则是 'If date is Sunday, make the date minus 6 days'。否则保持原样。
如果你的输入是这样的-
<?xml version='1.0' encoding='UTF-8'?>
<root>
<createDate>2016-05-08</createDate>
</root>
然后您可以使用下面的数据编织代码来获取所需的日期。当日期是星期天时,从日期中减去 6 天 -
%dw 1.0
%output application/csv
---
{
row: {
date: (payload.root.createDate as :date) unless
(((payload.root.createDate as :date) as :string {format: "E"}) == 'Sun')
otherwise ((payload.root.createDate as :date) - |P6D|)
}
}
它会输出如下 -
date
2016-05-02