1
我使用Dataweave重新格式化从有效载荷将XML格式的节目期待:Dataweave XML-XML转换“无法强制将a:数组转换为:字符串”。
有效载荷
<reservation>
<id>1</id>
<begin_time>12:00 PM</begin_time>
<end_time>1:00 PM</begin_time>
<other_field>Misc. Data</other_field>
</reservation>
.
.
.
预期输出。
<reservation>
<id>1</id>
<begin_time>12:00 PM</begin_time>
<schedule>
<begin_time>12:00 PM</begin_time>
<end_time>1:00 PM</end_time>
</schedule>
</reservation>
.
.
.
Dataweave代码
%dw 1.0
%output application/xml
%namespace ns0 http://www.collegenet.com/r25
---
using (r = (flatten payload.ns0#reservations.*ns0#reservation))
Reservation: r groupBy $.ns0#reservation_id pluck {
id : $.ns0#reservation_id ,
StartTime: $.ns0#reservation_start_dt,
Schedule : {
ReservationStartDate : $.ns0#reservation_start_dt,
PreEventDate : $.ns0#pre_event_dt,
EventStartDate : $.ns0#event_start_dt,
PostEventDate : $.ns0#post_event_dt,
ReservationEndDate : $.ns0#reservation_end_dt
}
}
每当我尝试这个代码,我得到一个错误:
"Exception while executing: Reservation: r map { ^ Cannot coerce a :array to a :object."
当我尝试完全相同的代码,但转换成JSON,而不是XML,改造工程完美。如果我删除了该地图的代码,但它会加入同一标题下所有预订的所有ID。我不明白为什么Anypoint将xml解释为数组而不是对象。
当我想,我在执行了一个错误“异常:使用 (R =(拼合payload.ns0#保留* NS0#预约)。) ^ 对发现 '扁平化' 运营商 类型不匹配:空 required:array。“ 我想你在我的代码中发现了其他错误,原帖中的代码已被重新修复,以解决这个问题,但主要的错误仍然存在。 –
如果您至少可以发布正确的输入XML和输出格式,我可以提供更多帮助。 – AnupamBhusari