gpt4 book ai didi

sql - 如何通过 "nodes"命令在 SQL XML 查询中使用命名空间?

转载 作者:数据小太阳 更新时间:2023-10-29 02:05:54 27 4
gpt4 key购买 nike

我正在尝试从以下 XML 查询中查询字段(这实际上是一个网络服务调用):

<soap:Envelope xmlns:xsi="[schema]" xmlns:xsd="[shema]" xmlns:soap="[schema]">
<soap:Body>
<RunPackage xmlns="http://tempuri.org/">
<xmlDoc>
<Request>
<SubscriberCode>543253</SubscriberCode>
<CompanyCode>54325</CompanyCode>
<BranchName>TestBranchName</BranchName>
<TempWorksUserName>TempWorksUserName</TempWorksUserName>
[...]

使用以下 XML 查询:

WITH XMLNAMESPACES('[schema]' AS soap2, DEFAULT '[schema]')

SELECT TransactionID, T2.Loc.query('data(Request/SubscriberCode)') as 'SubscriberCode'
FROM TempWorksRequest
CROSS APPLY RequestXML.nodes('soap2:Envelope/soap2:Body/RunPackage/xmlDoc') as T2(Loc)

它运行但不返回任何结果!

如果我构建相同的查询但删除命名空间的东西,那么它就可以工作了。例如,以下工作正常:

<xmlDoc> <Request> <SubscriberCode>543253</SubscriberCode> <CompanyCode>54325</CompanyCode> <BranchName>TestBranchName</BranchName> [...]

SQL 查询:

-- Define a namespace for MITS so we can use the MITS namespace. WITH XMLNAMESPACES('[schema]' AS soap2, DEFAULT '[schema]')

SELECT TransactionID, T2.Loc.query('data(Request/SubscriberCode)') as 'SubscriberCode' FROM TempWorksRequest CROSS APPLY RequestXML.nodes('xmlDoc') as T2(Loc)

有什么想法吗?

最佳答案

找到问题感谢马克!命名空间必须显式声明。

新的 WORKING 查询:

WITH XMLNAMESPACES('[URI1]' AS ns, '[URI2]' AS soap) 

SELECT TransactionID,
T2.Loc.query('data(ns:SubscriberCode)') as 'SubscriberCode',
FROM TempWorksRequest
CROSS APPLY RequestXML.nodes('soap:Envelope/soap:Body/ns:RunPackage/ns:xmlDoc/ns:Request') as T2(Loc)

关于sql - 如何通过 "nodes"命令在 SQL XML 查询中使用命名空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/982910/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com