Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.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 使用sql变量插入多个xml节点时如何声明命名空间_Sql Server_Xml_Xml Dml - Fatal编程技术网

Sql server 使用sql变量插入多个xml节点时如何声明命名空间

Sql server 使用sql变量插入多个xml节点时如何声明命名空间,sql-server,xml,xml-dml,Sql Server,Xml,Xml Dml,我正在尝试将@newLinks插入@links中,但不确定如何在以下sql中声明前缀“xsi”: declare @links xml set @links = N'<Links/>'; declare @newLinks xml set @newLinks = N' <Link xsi:type="CustomLink"> <Name>Foo</Name> </Link> <Link xsi:type="CustomLin

我正在尝试将
@newLinks
插入
@links
中,但不确定如何在以下sql中声明前缀“xsi”:

declare @links xml
set @links = N'<Links/>';

declare @newLinks xml
set @newLinks = N'
<Link xsi:type="CustomLink">
  <Name>Foo</Name>
</Link>
<Link xsi:type="CustomLink">
  <Name>Bar</Name>
</Link>';

set @links.modify('
insert sql:variable("@newLinks")
into (/Links)[1]');

select @links;
我尝试了以下方法,但没有成功:

set @links.modify('
declare namespace xsi="http://www.w3.org/2001/XMLSchema-instance";
insert sql:variable("@newLinks")
into (/Links)[1]');

您可以在xml片段中使用
xmlns
属性来定义
xsi
前缀。该声明适用于所有子节点。片段中没有根节点,因此必须在两个
元素上定义它

declare @newLinks xml
set @newLinks = N'
<Link 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:type="CustomLink">
  <Name>Foo</Name>
</Link>
<Link 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:type="CustomLink">
  <Name>Bar</Name>
</Link>';
declare@newLinks xml
设置@newLinks=N'
福
酒吧
';
declare @newLinks xml
set @newLinks = N'
<Link 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:type="CustomLink">
  <Name>Foo</Name>
</Link>
<Link 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:type="CustomLink">
  <Name>Bar</Name>
</Link>';