我正在從Web服務接收數據。 XML進來是這樣的:從列表中創建XElement <T>其中T.property爲空
<data>
<item>
<code>a</code>
<price>2.89</price>
</item>
<item>
<code>a</code>
<price>2.89</price>
<colour>blue</colour>
</item>
</data>
所以,我們看到一個項目有一個額外的屬性顏色。
好的,這將轉換爲列表<項目>這是我得到它的點。
我需要將此列表轉換爲XDocument。
使用:
var xml = new XDocument(
new XDeclaration("1.0", "utf-16", "yes"),
new XElement("data",
from i in myList
select new XElement("item",
new XElement("price", i.price),
new XElement("code", i.code),
new XElement("colour", i.colour))));
(我從記憶中鍵入這一點,所以藉口拼寫)
這裏,錯誤,因爲i.colour爲空。
我該如何應對?
在此先感謝
格里夫
你什麼*想*到當'colour'爲'null'時發生? – AakashM 2011-06-16 11:28:20