我需要顯示空或零,而不是顯示空字符串。替換string.empty並顯示「空」使用LINQ到XML?
XML響應:
<Items>
<Item>
<ASIN>111</ASIN>
<ItemAttributes>
<Title>xxx</Title>
<ListPrice>
<Currency>USD</Currency>
<FormattedPrice>45.25</FormattedPrice>
</ListPrice>
</ItemAttributes>
<Variation>
<Item>
<ItemAttributes>
<Title>yes</Title>
</ItemAttributes>
</Item>
</Variation>
</Item>
<Item>
<ASIN>222</ASIN>
<ItemAttributes>
<Title>yyy</Title>
</ItemAttributes>
<Variation>
<Item>
<ItemAttributes>
<Title>No</Title>
</ItemAttributes>
</Item>
</Variation>
</Item>
<Items>
這裏是我的代碼,
var Price1 = xd.Descendants(ns + "ListPrice").Select(c => new
{
PPrice = (c.Element(ns + "FormattedPrice") != null) ?
c.Element(ns + "FormattedPrice").Value : **string.Empty**
}).ToList();
如何與像 「空」 或提前0。謝謝值替換的String.Empty。 如果「格式化價格」對於第二項不可用,則從Xml響應中獲得,它應該在列表中顯示或爲空。
哪種情況爲空,哪種情況爲0? –
@CuongLe如果條件失敗,這裏顯示string.empty。而不是我必須顯示任何文字它可能是「空」或數字「0」。 –
你可以把0放在這個地方? –