开发者

How to get the default xmlnamespace from an XML datatype using TSQL?

Consider the following TSQL:

declare @xml xml
select  @xml = '<test xmlns="http://this-is-the-default-namespace-uri">some data</test>'

select  x.value('namespace-uri(.)', 'varchar(100)')
from    @xml.nodes('.') x(x)

What I'm trying to get from the XML is the URI of the default namespace. This is the value of the xmlns attribute on the root element. The above select statement is returning an em开发者_JAVA技巧pty string. How can I get the actual value of the xmlns?


I'm not too familiar with how fn:namespace-uri() works but this seems to return what you want...

select  x.value('namespace-uri(.)', 'varchar(100)')
from    @xml.nodes('*[1]') x(x);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜