当我运行以下代码时,它显示错误
“调用目标已抛出异常”
我该怎么做才能解决这个问题?
public LinqToXml()
{
XDocument document = XDocument.Load(@"D:\\Data.xml");
#region Fetch All the Books
var books = from r in document.Descendants("book")
select new
{
Author = r.Element("author").Value,
Title = r.Element("title").Value,
Genere = r.Element("genre").Value,
Price = r.Element("price").Value,
PublishDate = r.Element("publish_date").Value,
Description = r.Element("description").Value,
};
foreach (var r in books)
{
com_xdocuments.Items.Add(r.PublishDate + r.Title + r.Author);
}
#endregion
}
答案 0 :(得分:0)
不应该是
XDocument document = XDocument.Load(@"D:\Data.xml");
两者都相同@"D:\Data.xml"
和"D:\\Data.xml"