Select from XElement with where statement using linq -
i have , xelement object built xml looking this:
<root> <oppurtunities> <oppurtunity> <title> account manager</title> <company>company name</company> <location>boston</location> <enddate>2013-04-11</enddate> <c>acce</c> <id>mnyn-95zl8l</id> <description>this detailed description...</description> </oppurtunity>
now need description value specific oppurtunity node, meaning want description id specific. need this:
//my xelement object called oppurtunities oppurtunities = new xelement((xelement)cache["oppurtunities"]); string id = request.querystring["id"]; //i want of course not working var description = (from job in oppurtunities .element("oppurtunities") .element("oppurtunity") .element("description") job.element("id") == id).singleordefault();
you have move .element("description")
further in query, allow id
condition work:
//i want of course not working var description = (from job in oppurtunities .element("oppurtunities") .elements("oppurtunity") job.element("id") == id select job.element("description")).singleordefault()
to compare element("id")
string use (string)xelement
conversion - it's gonna work when <id>
won't found:
where (string)job.element("id") == id
using xelement.value
throw nullreferenceexception
in situation.
Comments
Post a Comment