【问题标题】:XQuery [nodes()]: The name "s" does not denote a namespaceXQuery [nodes()]:名称“s”不表示名称空间
【发布时间】:2013-11-08 08:45:01
【问题描述】:

我有一个需要粉碎的 xml。但我收到此错误XQuery [nodes()]: The name "s" does not denote a namespace.

我有以下格式的xml

<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)

但是当尝试使用 xquery 将其切碎时,它给了我错误。

为了粉碎我写了以下查询:

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)

有人可以建议我可能有什么问题吗?提前致谢。

【问题讨论】:

    标签: xml sql-server-2008 xquery xquery-sql


    【解决方案1】:

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

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

    它仍在 MS SQL 2016 上运行。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-11-06
        • 1970-01-01
        • 1970-01-01
        • 2016-05-19
        • 1970-01-01
        • 2014-10-28
        • 1970-01-01
        相关资源
        最近更新 更多