开发者

SQL Server XML Declare Namespace

开发者 https://www.devze.com 2022-12-08 22:25 出处:网络
I would like to have a few namespaces available by default when running an XQuery in SQL Server 2005, is this possible?

I would like to have a few namespaces available by default when running an XQuery in SQL Server 2005, is this possible?

For example, I would like to do the following:

select * from TableWithXML
where
FieldWithXML.exist(
declare namespace nsp="http://www.example.com/exampleNamespace";
nsp:root/nsp:childnode) = 1

Without having to redeclare the na开发者_Python百科mespace each time, so that SQL will recognize nsp without me including the prolog each time.

Thoughts?


The xml and xsi namespaces are the only pre-defined namespaces that you do not have to declare yourself. All other namespaces must be explicitally declared in every query.

There are two ways to declare namespaces:

  1. via the declare statement inside the XQuery.
  2. via the WITH XMLNAMESPACES clause on the TSQL statement.
0

精彩评论

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