471,310 Members | 1,389 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,310 software developers and data experts.

Linq to Xml

Hello,

I am getting records from an SQL database using Linq.
I want to write these records in a XML file.

Each record would be a node in my XML file.
However, the attributes in the XML file have different names from the
columns of my object in the list.

How can I do this?

Thanks,
Miguel
Sep 6 '08 #1
1 1165
shapper <md*****@gmail.comwrote:
I am getting records from an SQL database using Linq.
I want to write these records in a XML file.

Each record would be a node in my XML file.
However, the attributes in the XML file have different names from the
columns of my object in the list.

How can I do this?
Assuming you've got a variable called "query" which does the relevant
SQL query, retrieving columns "Sql1", "Sql2" and you want to call them
"Xml1" and "Xml2":

XElement container = new XElement("container",
query.Select (sqlRow =new XElement("XmlNode",
new XElement("Xml1", sqlRow.Sql1),
new XElement("Xml2", sqlRow.Sql2))
);

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Sep 7 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Dave Johnson | last post: by
9 posts views Thread by =?Utf-8?B?cmF1bGF2aQ==?= | last post: by
reply views Thread by =?Utf-8?B?SHlwZXJjb2Rlcg==?= | last post: by
4 posts views Thread by =?Utf-8?B?RXJpYyBGYWxza2Vu?= | last post: by
14 posts views Thread by thj | last post: by
9 posts views Thread by Cirene | last post: by
3 posts views Thread by =?Utf-8?B?UGF1bCBQcmV3ZXR0?= | last post: by
4 posts views Thread by George | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.