惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Threatpost
V
Vulnerabilities – Threatpost
TaoSecurity Blog
TaoSecurity Blog
C
Cybersecurity and Infrastructure Security Agency CISA
P
Proofpoint News Feed
G
GRAHAM CLULEY
S
Securelist
P
Palo Alto Networks Blog
MongoDB | Blog
MongoDB | Blog
A
Arctic Wolf
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
WordPress大学
WordPress大学
Project Zero
Project Zero
T
Threat Research - Cisco Blogs
L
Lohrmann on Cybersecurity
C
Cyber Attacks, Cyber Crime and Cyber Security
F
Fortinet All Blogs
博客园 - 叶小钗
B
Blog RSS Feed
C
Cisco Blogs
Google DeepMind News
Google DeepMind News
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Apple Machine Learning Research
Apple Machine Learning Research
G
Google Developers Blog
K
Kaspersky official blog
D
Docker
Latest news
Latest news
Cisco Talos Blog
Cisco Talos Blog
T
Tor Project blog
Cyberwarzone
Cyberwarzone
Security Latest
Security Latest
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Spread Privacy
Spread Privacy
Microsoft Azure Blog
Microsoft Azure Blog
C
Check Point Blog
J
Java Code Geeks
Simon Willison's Weblog
Simon Willison's Weblog
T
Tenable Blog
Recent Announcements
Recent Announcements
T
Tailwind CSS Blog
H
Help Net Security
L
LINUX DO - 热门话题
T
The Exploit Database - CXSecurity.com
Jina AI
Jina AI
S
SegmentFault 最新的问题
MyScale Blog
MyScale Blog
NISL@THU
NISL@THU
美团技术团队
腾讯CDC

博客园 - Yunanw

某些版本的IIS可能有SessionID混淆的Bug 小觑数据库(SqlServer)查询语句执行过程 C#中Finally的一个不太常见的用法 通过表达式树实现的ObjectMapper 实际一个多态(或弱类型)ConfigurationElementCollection 通过P/Invoke调用32位C++ DLL时,一定要将平台改为X86 坑爹的面试题 在Windows2008 IIS7上部署.net 1.1 用Python 实现刷钻网上抢任务,并实现一个简单的限制使用时间的功能 Python几行代码打印出网卡的Mac地址 放大招,解决前同事签出TFS文件的问题 飞猪传书 Linq To xml 查询时需要注意的一点。 - Yunanw 自定义WinForm 下ListBox的行高 使用LogParser分析网站运行情况(比较简单) 重新装载VS的模板 咱也搞一个TransactionScope QQ斗地主记牌器(只支持角色版) - Yunanw - 博客园 实现支持会话的WebClient
应用SQLServer For XML 生成XML避免在C# 拼字符串
Yunanw · 2014-07-09 · via 博客园 - Yunanw

 最近在Review代码时,有一个功能是 查询数据库中一列,然后生成像

<rootelements>
     <col>a</col>
     <col>b</col>
      <col>c</col>
</rootelements>

开发人员查用的方法是,返回一个结果集,然后用循环的方法拼成这个字符串.然后再解析成XML

其实从05以后SQLServer对XML的支持大大增强.我们可以使用下面这一行SQL就返回上面的结果

Select col from table for xml xpath(‘’),root(‘rottelements')

xpath(‘') 表明每个行不再生成一个Xml根元素.假如写成

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>

更详细的可以看下面的微信帮助,写的很详细

http://msdn.microsoft.com/zh-cn/library/bb510462.aspx