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);
精彩评论