Linq to Xml

S

shapper

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
 
J

Jon Skeet [C# MVP]

shapper said:
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))
);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top