I’m using Linq to write XML to a file and I want only sections of the XML that contain values to be written (so no empty tags). Here’s what I have so far:
Public Class frm
Public Type As String
Public RowNumber As Integer
Public Col1 As String
Public Col2 As String
End Class
Dim bVisCustom2x7 As Boolean
Dim visform = <VisitorForm>
<Tabs>
<Tab>
<Type>Custom2x7</Type>
<Order></Order>
<Visibility><%= bVisCustom2x7.ToString %></Visibility>
<%= From frm In frm_list Where frm.Type = "Custom2x7" _
Select _
<Row>
<RowNumber><%= frm.RowNumber %></RowNumber>
<Col1><%= frm.Col1 %></Col1>
<Col2><%= frm.Col2 %></Col2>
</Row>
%>
</Tab>
<Tabs>
<VisitorForm>
So for example if frm.Col1 had no value stored how can I hide the Col1 tag from being written?
Thanks!
mg
It’s not the most elegant, but something like this would work:
The idea being that you can always put a <%= => expression nugget that returns either an XElement or Nothing, and it’ll only be inserted if a node was returned.