LINQ to XML

  • Thread starter Thread starter shapper
  • Start date Start date
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
 
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
 
Back
Top