Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 2005 如何使用XML FOR PATH向SQLServer2005中的根节点添加名称空间_Sql Server 2005_Xml Namespaces_For Xml Path - Fatal编程技术网

Sql server 2005 如何使用XML FOR PATH向SQLServer2005中的根节点添加名称空间

Sql server 2005 如何使用XML FOR PATH向SQLServer2005中的根节点添加名称空间,sql-server-2005,xml-namespaces,for-xml-path,Sql Server 2005,Xml Namespaces,For Xml Path,我已经使用SQLServer2005创建了Select…FORXMLPATH语句,需要向根节点添加几个名称空间和模式引用 xsi:schemaLocation="http://somewhere/v1/ schemaname.xsd" xmlns="http://somewhere/v1/" xmlns:lom="http://somewhere/lom/v1/" xmlns:a="http://somewhere/a/v1/" xmlns:cf="http://somewhere/cf/v1/

我已经使用SQLServer2005创建了Select…FORXMLPATH语句,需要向根节点添加几个名称空间和模式引用

xsi:schemaLocation="http://somewhere/v1/ schemaname.xsd"
xmlns="http://somewhere/v1/"
xmlns:lom="http://somewhere/lom/v1/"
xmlns:a="http://somewhere/a/v1/"
xmlns:cf="http://somewhere/cf/v1/"
xmlns:co="http://somewhere/co/v1/"
xmlns:hx="http://somewhere/hx/v1/" 
xmlns:m="http://somewhere/m/v1/" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
任何指点都将不胜感激


谢谢。

您可以尝试以下方式:

with xmlnamespaces
  (
   default 'http://somewhere/v1/',
  'http://somewhere/lom/v1/' as lom,
  'http://somewhere/a/v1/' as a,
  'http://somewhere/cf/v1/' as cf,
  'http://somewhere/co/v1/' as co,
  'http://somewhere/hx/v1/' as hx,
  'http://somewhere/m/v1/' as m,
  'http://www.w3.org/2001/XMLSchema-instance' as xsi
  )
select 'http://somewhere/v1/ schemaname.xsd' as "@xsi:schemaLocation"

for xml path('element')
结果:

<element xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xmlns:m="http://somewhere/m/v1/" 
         xmlns:hx="http://somewhere/hx/v1/" 
         xmlns:co="http://somewhere/co/v1/" 
         xmlns:cf="http://somewhere/cf/v1/" 
         xmlns:a="http://somewhere/a/v1/" 
         xmlns:lom="http://somewhere/lom/v1/" 
         xmlns="http://somewhere/v1/" 
         xsi:schemaLocation="http://somewhere/v1/ schemaname.xsd" />