LINQ to XML

S

shapper

Hello,

I am using LINQ to select records from a SQL database.
How can I create a XML file from it?

Thanks,
Miguel
 
C

Chris Dunaway

Hello,

I am using LINQ to select records from a SQL database.
How can I create a XML file from it?

Thanks,
Miguel

VB.Net supports Xml Literals which makes it easy to create XML.
Depending on what you want code like the following could be used.
Obviously you would need to change the xml and LINQ to suit your
needs. Note the classic asp like syntax that is used for the LINQ
query. C# doesn't support Xml literals so it's a little different
when using c#.

Sub SomeSub()

Dim xml = _
<?xml version="1.0" encoding="utf-8"?>
<rootnode>
<child1>
<%= From something In SomethingElse _
Where something.SomeProperty = "Some value" _
Select _
<child2>
Value of something <%= something.SomeProperty
%>
</child2>
<child3>
Value of something else <%=
something.SomeOtherProperty %>
</child3>
%>
</child1>
</rootnode>

Console.WriteLine(xml)

End Sub

Look for VB.Net and Xml Literals in conjunction with Linq and you
should find more examples.

Chris
 

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