I'm working on a LINQ to XML query where if I select the branch(parent node), only child nodes which is specific to that branch should highlight. I am developing an ASP.NET tool, in that I need to read an XML file, which reads parent node first, based on user selection, it will read child nodes, now the problem is if I select the parent node, it is reading all the child nodes from all parent node, so I need a query in which it should read respective child node upon selecting the branch
<branch name="TigerDrop">
<milestones>
<milestone name="BETA1"></milestone>
<milestone name="BETA2"></milestone>
</milestones>
</branch>
<branch name="EagleDrop">
<milestones>
<milestone name="RFLD"></milestone>
<milestone name="RFVD"></milestone>
</milestones>
</branch>
<branch name="LionDrop">
<milestones>
<milestone name="WIP2"></milestone>
<milestone name="WIP3"></milestone>
</milestones>
</branch>
I have tried like this,
public List<string> GetMilestones()
{
string inputFilePath = Server.MapPath(@"~/DropList.xml");
var elements = XDocument.Load(inputFilePath);
var result = (from item in elements.Descendants("milestones").Descendants("milestone").Where(item => (string) item == "branch")
.SelectMany(item => item.Parent.Elements("milestones").Elements("milestone"))).ToList();
return result;
}