在T-SQL中创建XML

时间:2018-03-28 10:42:54

标签: xml tsql sql-server-2005 xml-namespaces

我有点麻烦。我如何在这样的T-SQL中为XML文件创建根节点?

<Root xmlns="http://www.bla-bla.org" 
      xmlns:xs="http://www.w3.org/2001/XMLSchema" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

</Root>

此格式看起来像混合元素和命名空间。

1 个答案:

答案 0 :(得分:1)

  

此格式类似于混合元素和命名空间

不,您正在定义默认命名空间和两个带有前缀xsi:WITH XMLNAMESPACES(DEFAULT 'http://www.bla-bla.org' ,'http://www.w3.org/2001/XMLSchema' AS xs ,'http://www.w3.org/2001/XMLSchema-instance' AS xsi) SELECT 'blah' AS [@SomeAttribute] ,'dummy' AS SomeNode FOR XML PATH('SomeElement'),ROOT('root'); 的命名空间:

<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.bla-bla.org">
  <SomeElement SomeAttribute="blah">
    <SomeNode>dummy</SomeNode>
  </SomeElement>
</root>      

结果

{{1}}