开发者

xml serialization and for xml sql server

开发者 https://www.devze.com 2022-12-31 22:59 出处:网络
I\'ve a SQL statement that returns a xml result, for a serialized obj开发者_如何学编程ect.I want to add a attribute to an element, that reflects the type of the object \"xsi:type=table\" but i don\'t

I've a SQL statement that returns a xml result, for a serialized obj开发者_如何学编程ect.I want to add a attribute to an element, that reflects the type of the object "xsi:type=table" but i don't know how?


Could use some additional information on your problem, but here goes:

SELECT TOP 10 SomeId, COUNT(1) SomeValue
INTO #SomeTable
FROM (SELECT ABS(CAST(NEWID() AS binary(6)) % 1000) + 1 SomeId
      FROM sysobjects) sample
GROUP BY SomeId;

WITH XMLNAMESPACES (N'http://www.w3.org/2001/XMLSchema-instance' as xsi)
SELECT SomeId "@SomeId",
       -- here is where you specify the type to put in the attribute
       'table' "@xsi:type",
       SomeValue
FROM #SomeTable
FOR XML PATH('AnElement'), ROOT('RootElement')

DROP TABLE #SomeTable;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号