是否可以在VB.NET XML Literals中使节点可选?

时间:2011-11-22 21:37:00

标签: .net xml vb.net xml-literals

Dim task As XElement = <task>
                               <body>body</body>
                               <optional><%= myVar %></optional>

                           </task>

是否有<optional>

时删除myVar Is Nothing

1 个答案:

答案 0 :(得分:1)

您可以使用IIf

    Dim task As XElement = <task>
                               <body>body</body>
                               <%= IIf(String.IsNullOrEmpty(myVar), "", <optional><%= myVar %></optional>) %>
                           </task>