2

I have a xml that I need to shred. But I am getting this error XQuery [nodes()]: The name "s" does not denote a namespace.

I have xml in following format

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
   <s:Header>
      <a:Action s:mustUnderstand="1">urn:somename-com:Access.2012.Services.Patient.GetCensus</a:Action>
   </s:Header>
   <s:Body>
      <GetCensusByUnitResponse xmlns="urn:somename-com:Access.2012.Services.Patient">
         <GetCensusByUnitResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <BeddedPatients>
               <BeddedPatient>
                   ...
                   ...
                   ...
         </GetCensusByUnitResult>
      </GetCensusByUnitResponse>
</s:Body>
</s:Envelope>

;with xmlnamespaces('urn:Epic-com:Access.2012.Services.Patient' as ep,
        'http://www.w3.org/2003/05/soap-envelope' as s,
        'http://www.w3.org/2005/08/addressing' as a,
             'http://www.w3.org/2001/XMLSchema-instance' as i)

But when try to shred it using xquery it gives me the error.

To shred i have written following query:

select  x.n.value('(ep:AccommodationCode)[1]', 'varchar(128)') as accomdationCode
from @xml.nodes('/s:Envelope/s:Body/ep:GetCensusByUnitReeponse/ep:GetCensusByUnitResult/ep:BeddedPatients/ep:BeddedPatient') x(n)

Can somebody suggest me what might be problem? Thanks in advance.

4

2 回答 2

1

似乎Ankur在他/她的问题正文中添加了正确答案。T-sql 需要在select 语句之前声明命名空间:

WITH XMLNAMESPACES ( <XML namespace declaration item>  [ { , <XML namespace declaration item> }...] )

它仍在 MS SQL 2016 上工作。

于 2020-10-07T20:20:27.833 回答
0

您需要声明命名空间前缀,以便它们在查询执行上下文中可用(不仅仅是在文档中)。我不熟悉 SQL Server 的 XQuery 执行引擎,但它必须有一些用于声明名称空间的工具。您需要找到——或者——您可能会考虑使用本机 XML 数据库,这样您就不需要“分解”。

于 2013-12-07T13:06:26.657 回答