SQL Server for xml path 添加属性和值 [英] SQL Server for xml path add attributes and values
本文介绍了SQL Server for xml path 添加属性和值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个包含属性和值的 xml 节点.
I want to create an xml node that contains attributes as well as values.
示例:
<mynode attr1="hello">world</mynode>
我明白
SELECT 'hello' as '@attr1'
至少创建一个 mynode,但是如何附加world"呢?
creates at least mynode, but how to attach "world" then?
我试过了
SELECT 'world' as 'mynode/[@attr1=hello]'
但是没有用
推荐答案
这是一个基本的例子:
SELECT ( SELECT 'White' AS Color1,
'Blue' AS Color2,
'Black' AS Color3,
'Light' AS 'Color4/@Special',
'Green' AS Color4,
'Red' AS Color5
FOR
XML PATH('Colors'),
TYPE
),
( SELECT 'Apple' AS Fruits1,
'Pineapple' AS Fruits2,
'Grapes' AS Fruits3,
'Melon' AS Fruits4
FOR
XML PATH('Fruits'),
TYPE
)
FOR XML PATH(''),
ROOT('SampleXML')
有关更多信息,您可以访问此页面 SQL SERVER – 使用 T-SQL 创建 XML 文件的简单示例
Please, for more information you can visit this page SQL SERVER – Simple Example of Creating XML File Using T-SQL
这篇关于SQL Server for xml path 添加属性和值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文