Syntax for xquery with namespace in the node

白昼怎懂夜的黑 提交于 2020-01-06 16:26:01

问题


We are trying to get IdValue from sql query. We are using sql server 2005.

DECLARE @MyXML XML
SET @MyXML = '<Candidate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://ns.hr-xml.org/2007-04-15">
  <CandidateProfile>
    <ProfileId>
      <IdValue>9499063</IdValue>
    </ProfileId>
  </CandidateProfile>
  </Candidate>'

SELECT @MyXML.value('Candidate[1]/CandidateProfile[1]/ProfileId[1]','varchar(10)') AS Id

This is not working because of the name space in the Candidate tag.

Please let me know how to xquery with the namespace.


回答1:


    SELECT @MyXML.value(
    'declare namespace hr="http://ns.hr-xml.org/2007-04-15";
    hr:Candidate[1]/hr:CandidateProfile[1]/hr:ProfileId[1]','varchar(10)'
    ) 
    AS Id 

http://msdn.microsoft.com/en-US/library/ms189075(v=SQL.90).aspx



来源:https://stackoverflow.com/questions/5107790/syntax-for-xquery-with-namespace-in-the-node

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!