Dim task As XElement = <task>
<body>body</body>
<optional><%= myVar %></optional>
</task>
是否有<optional>
myVar Is Nothing
答案 0 :(得分:1)
您可以使用IIf
Dim task As XElement = <task>
<body>body</body>
<%= IIf(String.IsNullOrEmpty(myVar), "", <optional><%= myVar %></optional>) %>
</task>