如何配置ADF复制活动兼容XML节点格式导入数据到Azure SQL Database
ADF复制活动处理SOAP响应兼容单对象/数组节点配置方案
问题场景
在ADF中配置复制活动调用SOAP端点获取结果并存储到Azure SQL Database,SOAP响应XML格式如下:
<?xml version='1.0' encoding='UTF-8'?> <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"> <soapenv:Header/> <soapenv:Body> <ns:getTimesheetResponse xmlns:ns="http://services"> <ns:return xmlns:ax21="http://objects.services/xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ax21:Timesheet"> <ax21:endDate>2021/04/17</ax21:endDate> <ax21:entriesAccount xsi:nil="true"/> <ax21:entriesOther xsi:type="ax21:TimesheetEntry"> <ax21:entryHours>2.0</ax21:entryHours> <ax21:timesheetId>16532459835</ax21:timesheetId> </ax21:entriesOther> <ax21:entriesProject xsi:type="ax21:TimesheetEntry"> <ax21:entryHours>8.0</ax21:entryHours> <ax21:timesheetId>16532459835</ax21:timesheetId> </ax21:entriesProject> <ax21:entryHours>6.0</ax21:entryHours> <ax21:timesheetId>16532459835</ax21:timesheetId> </ax21:entriesProject> <ax21:startDate>2021/04/11</ax21:startDate> <ax21:summaryNotes></ax21:summaryNotes> <ax21:timesheetId>16532459835</ax21:timesheetId> <ax21:timesheetPeriodId>11507374</ax21:timesheetPeriodId> <ax21:userId>1767426015</ax21:userId> </ns:return> </ns:getTimesheetResponse> </soapenv:Body> </soapenv:Envelope>
其中<ax21:entriesOther>节点可能为单个对象或数组,<ax21:entriesProject>节点通常为数组。复制活动映射中将二者均设为集合引用时,<ax21:entriesOther>仅返回单条条目时无数据写入;映射为普通对象可正常运行,但无法兼容数组格式的返回结果。
原有配置参考:

可行解决方案
方案1:调整复制活动XML解析参数(优先推荐)
直接修改源端的XML解析规则,无需调整映射逻辑:
- 打开复制活动的源配置页签,找到XML格式对应的解析设置
- 开启
将单个节点作为数组处理配置项,开启后ADF解析XML时会自动将所有定义为集合的单节点包装成长度为1的数组,完全兼容单对象、数组两种返回格式 - 映射规则保持原有集合引用的配置即可正常写入数据
方案2:改用数据流做类型兼容处理
如果有额外的转换需求,可通过数据流实现更灵活的处理:
- 首先通过SOAP源拉取原始响应数据,不做提前解析
- 添加派生列转换,通过表达式判断节点类型,将单对象主动转为数组:
参考表达式:iif(isArray(entriesOther), entriesOther, array(entriesOther)) - 后续添加展开转换处理数组节点,再将字段映射到Azure SQL Database的目标表即可
内容的提问来源于stack exchange,提问作者MAK
相关产品推荐
相关产品推荐

