开发者

xml serialization and for xml sql server

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜