0
我正在使用linq代码解析XML文件。这是我的代码。我想绑定细节和图像列表。将system.collection.generic.list转换为列表
XmlSerializer serializer = new XmlSerializer(typeof(Notchs));
XDocument xmlDoc = XDocument.Parse(dataInXmlFile);
Notchs notchs = (Notchs)serializer.Deserialize(xmlDoc.CreateReader());
var query = from l in xmlDoc.Descendants("Category")
select new Notch
{
name = (string)l.Attribute("name").Value,
Titles = l.Element("Articles").Elements("article")
.Select(s => s.Attribute("title").ToString())
.ToList(),
Image = l.Element("Articles").Elements("article").Elements("thumb_image").Elements("image")
.Select(x => x.Attribute("url").ToString()).ToList()
};
foreach (var result in query)
{
Console.WriteLine(result.name);
foreach (var detail in result.Titles)
{
Console.WriteLine(detail);
}
}
NotchsList.ItemsSource = query.ToList();
我试过这个代码,但我得到了像下面的输出..但我想要的细节和图像列表。
name
System.Collection.Generic.List'1[string.system]
name
System.Collection.Generic.List'1[string.system]
请给我们一些示例数据(XML)以及您的输出应该如何。 – pescolino 2013-03-02 18:24:57
好吧,我会给你的, – user123 2013-03-04 04:20:49
@ user123:将来请编辑你的问题,而不是发布一个新的。如果你不知道如何编辑阅读[faq](http://stackoverflow.com/faq#howtoask)。 – pescolino 2013-03-04 17:23:44