我想用C#解析一個複雜的XML,我使用Linq來完成它。基本上,我做的到服務器的請求,我得到XML,這是代碼:用C解析複雜的XML#
XElement xdoc = XElement.Parse(e.Result);
this.newsList.ItemsSource =
from item in xdoc.Descendants("item")
select new ArticlesItem
{
//Image = item.Element("image").Element("url").Value,
Title = item.Element("title").Value,
Description = this.Strip(item.Element("description").Value).Substring(0, 200).ToString()
}
而這正是XML結構:
<item>
<test:link_id>1282570</test:link_id>
<test:user>SLAYERTANIC</test:user>
<title>aaa</title>
<description>aaa</description>
</item>
如何訪問到性能測試:例如link_id?
謝謝!
它看起來像'測試'是一個命名空間?如果是這樣,XName對象應該幫助你。 http://msdn.microsoft.com/en-us/library/system.xml.linq.xname.aspx – 2011-06-07 22:22:40
@伊萬,因爲這是行不通的。 – svick 2011-06-07 23:35:26