本文介绍了节点中具有命名空间的 xquery 的语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们正在尝试从 sql 查询中获取 IdValue.我们使用的是 sql server 2005.
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
由于 Candidate 标签中的命名空间,这不起作用.
This is not working because of the name space in the Candidate tag.
请告诉我如何使用命名空间进行 xquery.
Please let me know how to xquery with the namespace.
推荐答案
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
这篇关于节点中具有命名空间的 xquery 的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!