使用以下代码创建 xml 节点:
set @imageListXml = (
select
'IMG' + CAST( m.entry_id AS VARCHAR) as '@id',
(select title from titles where entry_id=m.tid) as 'textelements/title',
'TEST' as 'references/reference/@body',
'IMG' + CAST( m.entry_id AS VARCHAR) as 'references/reference/@value'
from media m
)
FOR XML PATH('image'), root('imagelist')
)
它创建了类似的东西:
<imagelist>
<image id="IMG1111">
<textelements>
<title>Test 1111</title>
</textelements>
<references>
<reference body="TEST" value="IMG1111" />
</references>
</image>
</imagelist>
我怎样才能把价值属性放在第一位,反之亦然?我认为这取决于我在 select 语句中首先陈述的内容。我对么?