我想用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