转换的查询/存储过程结果集为XML存储过程、结果、XML

2023-09-07 00:51:55 作者:海先森

我在寻找采取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和高达

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

HTTP://www.$c$cguru .COM / CSHARP / CSHARP / cs_linq / article.php / c13715 / http://colinmackay.co .UK /博客/ 2008/04/08 /介绍到LINQ到XML / HTTP://www.$c$cproject.com/KB/ LINQ / Introduction_LINQToXML.aspx

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

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

EXCEL的数据转换成XML的问题

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:

http://www.codeguru.com/csharp/csharp/cs_linq/article.php/c13715/ http://colinmackay.co.uk/blog/2008/04/08/introduction-to-linq-to-xml/ http://www.codeproject.com/KB/linq/Introduction_LINQToXML.aspx

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