我正在尝试构建一个相对简单的 XML 块以发送到 Web 服务。我正在使用 XML Literals,以下当前工作正常:
Dim OrderXML As XElement =
<PARAM>
<FLD NAME="CUSORDREF"><%= CustomerOrderNo %></FLD>
<FLD NAME="BPCORD"><%= CustomerCode %></FLD>
<GRP ID="SOH1_5">
<FLD NAME="YHOLDSTA">3</FLD>
</GRP>
<TAB ID="SOH4_1">
<%= From l In Me.OrderLines
Select
<LIN NUM=<%= l.Key %>>
<FLD NAME="ITMREF"><%= l.Value.Sku %></FLD>
<FLD NAME="QTY"><%= l.Value.ActualQuantity %></FLD>
</LIN>
%>
</TAB>
<GRP ID="ADB2_1">
<LST NAME="BPRNAM" SIZE="2" TYPE="Char">
<ITM><%= CustomerName %></ITM>
</LST>
<FLD NAME="CRY">GB</FLD>
<LST NAME="BPAADDLIG" SIZE="3" TYPE="Char">
<ITM><%= DeliveryAddress1 %></ITM>
<ITM><%= DeliveryAddress2 %></ITM>
<ITM><%= DeliveryAddress3 %></ITM>
</LST>
<FLD NAME="POSCOD"><%= DeliveryPostcode %></FLD>
<FLD NAME="CTY"><%= DeliveryCity %></FLD>
<FLD NAME="SAT"><%= DeliveryRegion %></FLD>
</GRP>
</PARAM>
但是,我想添加一个条件,该条件仅在<LIN>
某个条件为真时才包含该元素。所以,像这样:
Dim OrderXML As XElement =
<PARAM>
<FLD NAME="CUSORDREF"><%= CustomerOrderNo %></FLD>
<FLD NAME="BPCORD"><%= CustomerCode %></FLD>
<GRP ID="SOH1_5">
<FLD NAME="YHOLDSTA">3</FLD>
</GRP>
<TAB ID="SOH4_1">
<%= From l In Me.OrderLines
Select
<LIN NUM=<%= l.Key %>>
<FLD NAME="ITMREF"><%= l.Value.Sku %></FLD>
<FLD NAME="QTY"><%= l.Value.ActualQuantity %></FLD>
</LIN>
Where l.Value.ImportLine = True
%>
</TAB>
<GRP ID="ADB2_1">
<LST NAME="BPRNAM" SIZE="2" TYPE="Char">
<ITM><%= CustomerName %></ITM>
</LST>
<FLD NAME="CRY">GB</FLD>
<LST NAME="BPAADDLIG" SIZE="3" TYPE="Char">
<ITM><%= DeliveryAddress1 %></ITM>
<ITM><%= DeliveryAddress2 %></ITM>
<ITM><%= DeliveryAddress3 %></ITM>
</LST>
<FLD NAME="POSCOD"><%= DeliveryPostcode %></FLD>
<FLD NAME="CTY"><%= DeliveryCity %></FLD>
<FLD NAME="SAT"><%= DeliveryRegion %></FLD>
</GRP>
</PARAM>
但我似乎无法使语法正确。
任何人都可以帮忙吗?