开发者

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

开发者 https://www.devze.com 2023-02-17 12:32 出处:网络
Consider the following TSQL: declare @xml xml select@xml = \'<test xmlns=\"http://this-is-the-default-namespace-uri\">some data</test>\'

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

精彩评论

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