Recursion is one of the reasons I love VB.NET XML literals!
To perform recursion, you need a function that takes a ProfileItems collection and returns an XElement. You can then call this function recursively inside your XML literal.
In addition, for recursion to work, GetProfileItems and GetDependencies must have the same name (rename one of them) and display with the same Xml element structure. Here's what the recursive function looks like:
Function GetProfileItemsElement(ByVal Items As List(Of ProfileItem) As XElement Return <items> <%= From i In Items _ Select <item> <name><%= i.Name %></name> <!-- other elements here --> <%= GetProfileItemsElement(i.GetDependencies) %> </item> %> </items> End Function
The recursion will end when you go to an element that returns an empty list for the GetDependencies function. In this case, the nested items element will be empty: <items/> . XML literals are smart enough to combine the start and end tags of items when there are no children.
Coder dennis
source share