Linq never finding element in XDocument

loveispoison

New Member
I have the following \[code\]XDocument\[/code\] called \[code\]XDoc\[/code\]:\[code\]<?xml version="1.0" encoding="utf-8"?> <DatabaseList> <Database DatabaseName="c2501_data"> <Plugin PluginName="FooPlugin" LastRun="1/21/2013 3:22:08 PM" /> <Plugin PluginName="SpecialPlugin" LastRun="2013-01-21T15:22:09.3791103-05:00" /> <Plugin PluginName="BarPlugin" LastRun="2013-01-21T15:23:13.0964814-05:00" /> </Database></DatabaseList>\[/code\]I'm writing a program that searches to see when the last time a plugin was run on a database, if at all. I use the following two pieces of code to figure out if an entry exists for a plugin on a database:\[code\] var h = (from el in XDoc.Root.Elements("Database") where el.Element("Plugin").Attribute("PluginName").Valuehttp://stackoverflow.com/questions/14446759/=="FooPlugin" && el.Attribute("DatabaseName").Valuehttp://stackoverflow.com/questions/14446759/=="c2501_data" select el.Element("Plugin")); var e = (from el in XDoc.Root.Elements("Database") where el.Element("Plugin").Attribute("PluginName").Valuehttp://stackoverflow.com/questions/14446759/=="BarPlugin" && el.Attribute("DatabaseName").Value =http://stackoverflow.com/questions/14446759/="c2501_data" select el.Element("Plugin")); if ((from el in XDoc.Root.Elements("Database") where el.Element("Plugin").Attribute("PluginName").Value =http://stackoverflow.com/questions/14446759/="BarPlugin" && el.Attribute("DatabaseName").Value =http://stackoverflow.com/questions/14446759/="c2501_data" select el.Element("Plugin")).Count() == 0) { XElement SpecialPlugin = new XElement("Plugin", new XAttribute("PluginName", "BarPlugin"), new XAttribute("LastRun", DateTime.Now)); var CurNode = from node in XDoc.Root.Elements("Database") where (string)node.Attribute("DatabaseName").Value =http://stackoverflow.com/questions/14446759/="c2501_data" select node; foreach (var node in CurNode) node.Add(SpecialPlugin); XDoc.Save(RuntimesPath); //XDoc.Root.Elements("Database").Attribute("DatabaseName"). }\[/code\]The problem that I'm having is that even though there is clearly an entry for \[code\]BarPlugin\[/code\], the count will always return 0 and \[code\]e\[/code\] will always be unable to create an enumberable. Can anyone explain to me why this might be? \[code\]FooPlugin\[/code\] always works correctly and returns the Plugin information for \[code\]h\[/code\]. Thanks for any help.
 
Back
Top