转换的查询/存储过程结果集为XML [英] Convert query/stored procedure result set to XML

查看:121
本文介绍了转换的查询/存储过程结果集为XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找采取SQL Server存储过程的结果,并将其转换成XML在.NET / C#

我很感兴趣的是什么标准库中有.NET帮助生成XML的细节,如果有任何外部库或技巧,可以帮助自动化从结果转换设置为XML。

我看在过去的SQL Server(05)中的XML选项,但他们不是为了什么我需要足够强大。

解决方案

有两种基本技术开箱.NET中,将允许您创建XML。在这两种情况下,你不会得到周围写了相当多的code。

1)的XmlDocument 的办法,例如,在 XML DOM做事为主的方式。您创建一个XmlDocument的,创建节点,设置属性,创建子节点等,并保存所有磁盘进行到底。

优点:适用于.NET 1.x和起来,是相当wides $ P $垫和知名 缺点:有点笨拙,让你整个XML结构的内存

请参阅详细信息在 MSDN文档并在网络上无数的文章和博客

2),然后是新的 LINQ到XML 的办法,在这里您将使用LINQ的语句文档。这是在.NET 3.5提供了而已,有些人喜欢它,其他的恨它有很多的激情:-)

优点:如果你喜欢LINQ,感觉很自然,更直接比XML DOM方法 缺点:只能在.NET 3.5和高达

查看主题的一些文章和博客文章:

当然,其它更多在那里 - 只是兵或谷歌的LINQ to XML

I'm looking to take the result of a SQL Server stored procedure and transform it into XML in .NET/C#

What I'm interested in is what standard libraries there are in .NET to help with the specifics of generating XML and if there any external libraries or tricks that can help automating the transformation from result set to XML.

I've looked at the XML options within SQL Server (05) in the past but they are not powerful enough for what I require.

解决方案

There's basically two technologies out of the box in .NET that will allow you to create XML. In both cases, you won't get around writing quite a bit of code.

1) The XmlDocument approach, e.g. the XML DOM based way of doing things. You create a XmlDocument, create nodes, set attributes, create child nodes and so forth, and save all to disk in the end.

Pros: works on .NET 1.x and up, is quite widespread and well-known Cons: is a bit "clunky", keeps you whole XML structure in memory

See more info in the MSDN docs and countless articles and blog posts on the web

2) Then there's the newer Linq-to-XML approach, where you create your document using Linq statements. This is available in .NET 3.5 and up only, and some folks love it, other hate it with a lot of passion :-)

Pros: if you like LINQ, it feels quite natural and more "direct" than the XML DOM approach Cons: only on .NET 3.5 and up

See some articles and blog posts on the topic:

Certainly lots more out there - just bing or google for "linq to xml".

这篇关于转换的查询/存储过程结果集为XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆