使用 mule 4 将新节点添加到 xml 负载时缺少属性值
Attribute values are missing while adding new node to xml payload using mule 4
我正在尝试使用以下 dataweave 代码将新的子节点(ValidationError)添加到现有的 xml 有效负载:
%dw 2.0
var errormessage = "Rating Service Exception Error. Please contact support."
output application/xml writeDeclaration=false
---
DTOApplication : payload.DTOApplication ++ { ValidationError @(TypeCd: "Validation", Name: "Rate Service Exception Error", Msg: errormessage, SubTypeCd: "ERROR") :null}
ValidationError 子节点追加完美,但根节点 DTOApplication 的属性值缺失。
输入负载:https://github.com/Manikandan99/Map_request/blob/main/request_payload.xml
预期响应:https://github.com/Manikandan99/Map_request/blob/main/Expected_response.xml
新的子节点是ValidationError :
<ValidationError TypeCd="Validation" Name="Rate Service Exception Error" Msg="Rating Service Exception Error. Please contact support." SubTypeCd="ERROR"/>
关于如何使用 dataweave 2.0 将 ValidationError 子节点附加到现有有效负载而不丢失 DTOApplication 的属性值有什么想法吗?
你能试试下面的代码吗,它给出了预期的输出
%dw 2.0
var errormessage = "Rating Service Exception Error. Please contact support."
output application/xml writeDeclaration=true
---
payload mapObject ((value, key, index) ->
(key): value ++ {
ValidationError @(TypeCd: "Validation", Name: "Rate Service Exception Error", Msg: errormessage, SubTypeCd: "ERROR"): null
}
)
您的脚本存在的问题是它使用了节点 DTOApplication 的值但忽略了它具有的属性。我提供了一个简单的修复,但@Anurag Sharma 解决方案似乎更好,因为它是通用的。
%dw 2.0
var errormessage = "Rating Service Exception Error. Please contact support."
output application/xml writeDeclaration=false
---
{
DTOApplication @((payload.DTOApplication.@)) : payload.DTOApplication ++ { ValidationError @(TypeCd: "Validation", Name: "Rate Service Exception Error", Msg: errormessage, SubTypeCd: "ERROR") :null}
}
我正在尝试使用以下 dataweave 代码将新的子节点(ValidationError)添加到现有的 xml 有效负载:
%dw 2.0
var errormessage = "Rating Service Exception Error. Please contact support."
output application/xml writeDeclaration=false
---
DTOApplication : payload.DTOApplication ++ { ValidationError @(TypeCd: "Validation", Name: "Rate Service Exception Error", Msg: errormessage, SubTypeCd: "ERROR") :null}
ValidationError 子节点追加完美,但根节点 DTOApplication 的属性值缺失。
输入负载:https://github.com/Manikandan99/Map_request/blob/main/request_payload.xml
预期响应:https://github.com/Manikandan99/Map_request/blob/main/Expected_response.xml
新的子节点是ValidationError :
<ValidationError TypeCd="Validation" Name="Rate Service Exception Error" Msg="Rating Service Exception Error. Please contact support." SubTypeCd="ERROR"/>
关于如何使用 dataweave 2.0 将 ValidationError 子节点附加到现有有效负载而不丢失 DTOApplication 的属性值有什么想法吗?
你能试试下面的代码吗,它给出了预期的输出
%dw 2.0
var errormessage = "Rating Service Exception Error. Please contact support."
output application/xml writeDeclaration=true
---
payload mapObject ((value, key, index) ->
(key): value ++ {
ValidationError @(TypeCd: "Validation", Name: "Rate Service Exception Error", Msg: errormessage, SubTypeCd: "ERROR"): null
}
)
您的脚本存在的问题是它使用了节点 DTOApplication 的值但忽略了它具有的属性。我提供了一个简单的修复,但@Anurag Sharma 解决方案似乎更好,因为它是通用的。
%dw 2.0
var errormessage = "Rating Service Exception Error. Please contact support."
output application/xml writeDeclaration=false
---
{
DTOApplication @((payload.DTOApplication.@)) : payload.DTOApplication ++ { ValidationError @(TypeCd: "Validation", Name: "Rate Service Exception Error", Msg: errormessage, SubTypeCd: "ERROR") :null}
}