挑选一个我不理解的例外。如果有人能把它放在心上,真的会有所帮助。使用其他经过测试的RSS源并且没有问题,但是最新的测试候选人让我头疼。
Line 499 is the one in the query: select new {
Line 517 is the opening statement of the foreach.
----在System.Xml.Linq.XNamespace.op_Addition(XNamespace ns,String localName)at at rssRepub.MainForm。<> c__DisplayClassd.b__2(XElement item)in c:\ Documents and Settings \ Andrew Seabrook \ My 文档\研发\ rssPub \ rssRepub_0.5 \ rssRepub \ MainForm.cs:行 499在 System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
在rssRepub.MainForm.Completed(Object sender,AsyncCompletedEventArgs e)在c:\ Documents and Settings \ Andrew Seabrook \ My 文档\研发\ rssPub \ rssRepub_0.5 \ rssRepub \ MainForm.cs:行 517----值不能为空。参数名称:ns
try
{
toolStripStatusLabelMain.Text = "Download completed!";
XslCompiledTransform transform = new XslCompiledTransform();
transform.Load(INSTALLPATH + "id.xslt");
transform.Transform(INSTALLPATH + "tempfeed.txt", INSTALLPATH + "clean.xml");
XDocument doc = XDocument.Load(INSTALLPATH + "clean.xml");
Dictionary<String, String> dbdata = new Dictionary<String, String>();
var db = new MSAccess();
string feedID = db.ExecuteScalar("SELECT feedID FROM Feeds WHERE feedURL = '" + tvMain.SelectedNode.Tag.ToString() + "'");
XNamespace dcNs = doc.Element("rss").GetNamespaceOfPrefix("dc");
XNamespace slashNs = doc.Element("rss").GetNamespaceOfPrefix("slash");
//XNamespace slashNs = "http://purl.org/rss/1.0/modules/slash/";
var data = from item in doc.Root.Descendants().First(i => i.Name.LocalName == "channel").Elements().Where(i => i.Name.LocalName == "item")
select new {
Title = item.Elements().First(i => i.Name.LocalName == "title").Value,
Link = item.Elements().First(i => i.Name.LocalName == "link").Value,
PublishDate = ParseDate(item.Elements().First(i => i.Name.LocalName == "pubDate").Value),
Creator = item.Element(dcNs + "creator").Value,
Guid = item.Elements().First(i => i.Name.LocalName == "guid").Value,
Description = item.Elements().First(i => i.Name.LocalName == "description").Value,
//Content = item.Elements().First(i => i.Name.LocalName == "content").Value,
Content = item.Elements().First(i => i.Name.LocalName == "description").Value,
//Comments = item.Element("slash:comments").Value
Comments = item.Element(slashNs + "comments").Value,
//Comments = item.SelectSingleNode("slash:comments", nameSpace).InnerText
Categories = (from category in item.Elements("category")
orderby category.Value
select category.Value).ToList()
};
foreach (var item in data)
{
var csv = string.Join( ";", item.Categories );
//add feed to database
dbdata.Add("fiFeedID", feedID);
dbdata.Add("fiTitle", item.Title);
dbdata.Add("fiLink", item.Link);
dbdata.Add("fiPubDate", item.PublishDate.ToString());
//if (item.Creator != null)
dbdata.Add("fiCreator", item.Creator);
dbdata.Add("fiGuid", item.Guid);
dbdata.Add("fiDescription", item.Description);
dbdata.Add("fiContent", item.Content);
//if (item.Comments != null)
dbdata.Add("fiComments", item.Comments);
dbdata.Add("fiTags",csv);
try
{
db.Insert("FeedItems", dbdata);
}
catch(Exception crap)
{
OutCrap(crap);
}
dbdata.Clear();
}
UpdateStatus("Fetching " + tvMain.SelectedNode.Name);
UpdateDGVMain();
}
catch (Exception crap)
{
OutCrap(crap);
}