I have an xml that looks like this:
<ProductTemplate ProductName="FlamingoWhistle" Version="1.8.02" >
<Whistle Type="Red" Version="3.0.5" />
<Size Type="Large" Version="1.0" />
<Whistle Type="Blue" Version="2.4.3" />
</ProductTemplate>
How can I check if type equals red, return the version for that type?
This is what I have tried but fails if the element isn't first
XElement root = XElement.Load(path);
if (XPathSelectElement("Whistle").Attribute("Type") == "Blue")
{
Console.WriteLine(XPathSelectElement("Whistle").Attribute("Version").value));
}
else
{
Console.WriteLine("Sorry, no FlamingoWhistle in that color");
}