1
如何修改下面的查詢以正確處理其中一篇文章中缺少「摘要」元素的情況?現在,當發生這種情況時,我得到一個「未設置爲對象實例的對象引用」。Linq2XML missing element
var articles = from article in xmlDoc.Descendants("Article")
select new {
articleId = article.Attribute("ID").Value,
heading = article.Element("Heading").Value,
summary = article.Element("Summary").Value,
contents = article.Element("Contents").Value,
cats = from cat in article.Elements("Categories")
select new {
category = cat.Element("Category").Value
}
};
哇...謝謝。快速準確! – Steve 2010-12-22 21:26:15