开发者

How to create an xml file from a database table using linq?

I have a sql server 2005 database which contains a user开发者_如何学Python table.. Is it possible to create xml file from the user table? It contains columns like name,age,emailId,mob no etc.. Any suggestion?


This article may well help you..

http://jacquesbron.com/blog/database/linq-to-sql-and-linq-to-xml-in-action-from-database-to-xml/

I would use Entity Framework or Linq to SQL to get the data out of the database, then use linq to xml to create the desired xml output.


Assuming you can load the data from the DB table, then Linq to XML is exactly what you need. Check out the System.Xml.Linq namespace.

There are loads of tutorials around, but looking at the MSDN reference for XDocument isn't a bad place to start:

http://msdn.microsoft.com/en-us/library/system.xml.linq.xdocument.aspx

I found this tutorial useful for getting me going when I first needed to do this:

http://www.hookedonlinq.com/LINQtoXML5MinuteOverview.ashx


Just serialize it. XmlSerializer or DataContractSerializer may help.


Consider just using an ADO.NET DataSet. It's got built-in XML serialization, and a bunch of other stuff that comes in handy when you're interoperating with a database.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜