c# - LINQ to XML Select Nodes by duplicate child node attributes -


need pull out employees have pager.

 <employees>   <employee>     <name>michael</name>         <phone type="home">423-555-0124</phone>     <phone type="work">800-555-0545</phone>     <phone type="mobile">424-555-0546</phone>     <phone type="cell">424-555-0547</phone>     <phone type="pager">424-555-0548</phone>   </employee>  <employee>     <name>jannet</name>         <phone type="home">423-555-0091</phone>     <phone type="work">800-555-0545</phone>   </employee> </employees> 

i've got linq phone nodes have pager , can employees. can't wrap head aroud drilling down phone node still selecting employee node?

 var data = xelement.load(@"employee.xml" ); var whohaspager = teammember in data.elements("employee")                 (string)teammember.element("phone").attribute("type") == "pager"                 select teammember; 

try this:

var whohaspager = teammember in data.elements("employee")                   teammember.elements("phone").any(x => x.attribute("type").value == "pager")                   select teammember; 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

c++ - How to modify context menu of internet explorer using IDocHostUIHandler::ShowContextMenu? -

c# - Asterisk click to call -