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

Azure Data Factory V2处理XML至Azure SQL的申请人数据映射问题

解决方案:ADF复制活动中XML多节点条件提取兼容处理

核心配置方案

在ADF复制活动的TabularTranslator映射中,使用xpath函数结合first和coalesce,精准按Type属性过滤节点,同时兼容单个/多个节点的解析场景:

  1. 主申请人姓名(必存在)
    用first函数确保无论单个还是多个<Applicant>节点,都能取到Type="primary"的匹配项:

    first(xpath(root, '//Applicant[@Type="primary"]/FirstName/text()'))
    
  2. 共同借款人姓名(可选)
    用coalesce处理无共同借款人的场景,返回空值而非导致主申请人数据异常:

    coalesce(first(xpath(root, '//Applicant[@Type="coBorrower"]/FirstName/text()')), '')
    

完整TabularTranslator JSON配置示例

"translator": {
    "type": "TabularTranslator",
    "mappings": [
        {
            "source": {
                "path": "//application_number/text()"
            },
            "sink": {
                "name": "application_number",
                "type": "String"
            }
        },
        {
            "source": {
                "path": "//generated_date/text()"
            },
            "sink": {
                "name": "generated_date",
                "type": "String"
            }
        },
        {
            "source": {
                "expression": "first(xpath(root, '//Applicant[@Type=\"primary\"]/FirstName/text()'))"
            },
            "sink": {
                "name": "applicant_primary_first_name",
                "type": "String"
            }
        },
        {
            "source": {
                "expression": "coalesce(first(xpath(root, '//Applicant[@Type=\"coBorrower\"]/FirstName/text()')), '')"
            },
            "sink": {
                "name": "applicant_coborrower_first_name",
                "type": "String"
            }
        }
    ]
}

问题根源分析

你之前的配置失效原因在于ADF对XML节点的解析逻辑:

  • 当仅存在单个<Applicant>节点时,ADF将其解析为标量值而非数组,此时用索引[0]取值会返回空。
  • 当存在两个节点时,ADF解析为数组,索引[0]能取到primary节点,但单节点场景下失效。
  • 直接使用过滤表达式未结合first函数时,单节点场景下的返回值类型不兼容,导致取值失败。

验证步骤

  1. 测试仅含primary申请人的XML文件,确认applicant_primary_first_name正常赋值,applicant_coborrower_first_name为空。
  2. 测试含primary+coBorrower的XML文件,确认两个字段均正确提取对应值。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.18 07:58:09