我有一个类似于以下的XML结构
James 12 SELECT Name as 'name' Age as 'description xsi:type="me:age"' Height as 'description xsi:type="me:height"' FOR XML PATH('person')
但它给我一个关于'description xsi'命名空间丢失的错误.有没有办法使用FOR XML PATH实现这一点.实际查询比这个例子复杂得多,需要花费很多精力才能改变.
谢谢
FOR XML PATH有时候有点困难(至少从我所知道的).这可能会让你到达那里:
WITH XMLNAMESPACES('uri' as xsi) SELECT 'me:age' AS 'description/@xsi:type' ,age AS 'description' ,name AS 'name' ,'me:height' AS 'description/@xsi:type' ,height AS 'description' FROM #test FOR XML PATH('person')
生产:
32 Alice 6 Foot 24 Bob 5 Feet 5 Inches