I have a problem parsing a XML file using Linq to XML.
My XML structure looks like:
<Module>
<Variable Name="Variable1" Value="True" />
<Variable Name="Variable2" Value="True" />
<Variable Name="Variable3" Value="True" />
</Task>
<Task Name="Task1">
<Variable Name="Task1Variable1" Value ="True" />
<Variable Name=" Task1Variable2" Value ="True" />
</Task>
<Task Name="Task2">
<Variable Name="Task2Variable1" Value ="True" />
<Variable Name=" Task2Variable2" Value ="True" />
</Task>
</Module>
What I intend to do is to get the value of each Variable Name attribute. So for the elements that are directly under the node Module it works fine with
var variables = (from cfg in _xElements.Descendants("Module").Elements("Variable")
select cfg.Attribute("Name"));
The problem starts with the Variable Name attributes that are under the Task nodes because I also need the information about the Task Name.
So what I would like to get is the information about the Variable name plus the information about the Task Name that is the parent node of the variable element.
Is there a way to get this done with Linq?