You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ADF中XML查询转换失败,使用replace函数仍报错求助

问题与解决方法

问题详情

存在一个字符串类型变量,定义如下:

{
    "variableName": "test",
    "value": "<?xml version=\"1.0\" encoding=\"utf-8\"?> <fetch version=\"1.0\" output-format=\"xml-platform\" mapping=\"logical\" aggregate=\"true\" distinct=\"false\"> <entity name=\"account\"> <attribute name=\"ownerid\" alias=\"account\" aggregate=\"count\" /> <filter type=\"and\"> <condition attribute=\"ownerid\" operator=\"not-null\" /> </filter> <link-entity name=\"team\" from=\"teamid\" to=\"owningteam\" link-type=\"inner\" alias=\"ae\"> <filter type=\"and\"> <condition attribute=\"teamtype\" operator=\"eq\" value=\"0\" /> <condition attribute=\"name\" operator=\"like\" value=\"%xyz%\" /> </filter> </link-entity> </entity> </fetch>"
}

传递该XML内容时,使用表达式 @xml(replace(variables('test'),'\', '' )) 处理转义符,出现以下错误:

ErrorCode=UserErrorInvalidValueInPayload,'Type=Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message=Failed to convert the value in 'query' property to 'System.String' type. Please make sure the payload structure and value are correct.,Source=Microsoft.DataTransfer.DataContracts,''Type=System.InvalidCastException,Message=Object must implement IConvertible.,Source=mscorlib,'

错误原因

@xml() 函数会将合法的XML字符串转换为XML节点对象,但目标属性query要求传入的是System.String类型,类型不匹配直接导致转换失败。

解决方法

无需使用@xml()函数,直接清理转义符后传递字符串即可。变量中的内容本身是带转义的XML字符串,去除\后就是合法的XML格式字符串,完全符合目标属性的类型要求。

正确表达式:

@replace(variables('test'), '\', '')

内容的提问来源于stack exchange,提问作者josh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 07:54:56