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
Post a Comment