Recently, when review code, there was a function of querying a column in the database and then generating a
<rootelements>
<col>a</col>
<col>b</col>
<col>c</col>
</rootelements>
The developer does this by returning a result set and then using the loop method to spell the string. Then parse to XML
In fact, SQL Server support for XML has been greatly enhanced since 05. We can use the following line of SQL to return the results above
Select col from table for XML XPath ('), Root (' rottelements ')
XPath (') indicates that each row no longer generates an XML root element. If written
Select col from table for XML XPath (), Root (' rottelements ')
<rootelements>
<row>
<col>a</col>row
</row>
<row>
<col>b</col>row
</row>
<row>
<col>c</col>row
</row>
</rootelements>
In more detail can see the following help, written in very detailed
http://msdn.microsoft.com/zh-cn/library/bb510462.aspx