Lets say you have an XML like like this:
<data>
<messages>
<message name="Person" id="P">
<field name="FirstName" required="Y" />
<field name="LastName" required="Y" />
<field name="Sex" required="N" />
</message>
<message name="Car" id="C">
<field name="Make" required="Y" />
<field name="Model" required="Y" />
<field name="Year" required="N" />
</message>
</messages>
</data>
Using Linq, how would you get a list of all required field names for Person?
I just started playing with LINQ/XML today this is about as far as Ive gotten.
var q = from c in loaded.Descendants("field")
where (string)c.Attribute("required") == "Y" &&
// how to check the parent node (message) has an attribute (id="P")
select (string)c.Attribute("name");
foreach (string name in q)
Console.WriteLine(name);
This answer is totally wrong considering the questioner changed his xml. Should I delete this.
Adding the Xml I used because there is some confusion over the right solution.