如何解析嵌入在 nvarchar 列中的 XML?

问题描述 投票:0回答:1

我目前正在解决一个问题,在阅读官方文档和在线查看主题后我无法解决这个问题,我会尝试尽可能清晰:

我正在使用 Azure Synapse Analytics,并创建了一个从 SQL Server 检索数据的源,如下所示:

enter image description here

我的源到接收器的映射是:

enter image description here

现在,在“请求”列中,有一个以 XML 格式嵌入的字符串,如下所示:

enter image description here

我试图解决的问题是我需要为 XML 字符串中的每个节点创建新列,例如我需要创建一个名为“MSP”的新列,其值“U678202”取自“codiceMSP” " XML 字符串中的节点,等等。 所以我创建了一个新的数据流并配置了源和解析转换,如下所示:

enter image description here

我创建了一个源块,从我的 Azure 存储中复制的数据中获取数据,然后创建了一个解析转换块来解析字符串中嵌入的 XML 数据并从中创建新列。问题是 XML 不是常规格式,我无法进行解析。我尝试设置命名空间,但“codiceMSP”的值不会解析到新的 MSP 列中。我做错了什么?如何配置 XML 解析转换以读取请求字符串内的节点?网上关于这个具体案例的信息并不多,任何帮助将不胜感激。

提前感谢您的帮助

致以诚挚的问候

xml azure azure-data-factory azure-synapse azure-synapse-analytics
1个回答
0
投票

根据您的要求,您可以使用以下方法:

  • 首先添加ADLS中存储xml的源数据集。
  • 添加派生列转换,您将从 XML 字符串中删除命名空间,如下所示:
replace(replace(coilumnname,'ns1:',''),'SOAP-ENV:','')

enter image description here

  • 然后添加解析转换以使用以下表达式从 XML 中提取列:
(Envelope as (Body as (ConfermaPagamentoFattura as (codiceMSP as string,
numerodocumento as string,
tipodocumento as string,
datadocumento as string
societa as string,
datapagamento as string,
numerotransazione as string,
importodocumento as double))))

enter image description here

  • 然后添加派生列以使用上述列为每个实体创建单独的列: enter image description here

最终输出:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.