This has a bit to do with SQL Server - normal behavior - this is what you see - column names will be used as the names of the XML elements.
If you really want all the XML elements to be named the same, you will need to use the code something like this:
SELECT 'id' AS 'field/@name', id AS 'field', '', 'version' AS 'field/@name', version AS 'field', '', 'property' AS 'field/@name', property AS 'field', '', ... and so on .... FROM Person.Person FOR XML PATH('row'),ROOT('resultset')
This is necessary to make sure that the column name is used as the name attribute in the <field> element, and an empty string is needed so that the SQL XML parser is not confused about which name attribute belongs to that element ...
marc_s
source share