@Festus Hagen , you could try to use XContainer.Descendants Method to use XDocument to get what you want.
Here is a code example you could refer to.
static void Main(string[] args)
{
string value1 = ProductComponent(255, 1, 1);
string value2 = ProductComponent(255, 1, 2);
string value3 = ProductComponent(254, 1, 3);
Console.WriteLine(value1);
Console.WriteLine(value2);
Console.WriteLine(value3)
}
public static string ProductComponent(int product, int component, int index)
{
XDocument doc = XDocument.Load("D:\\test.xml");
var result = doc.Descendants("PRODUCT").Where(i => Convert.ToInt32(i.Attribute("id").Value, 16) == product)
.Descendants("COMPONENTS").Where(i => Convert.ToInt32(i.Attribute("id").Value, 16) == component).Descendants("COMPONENT").Where(i =>
Convert.ToInt32(i.Attribute("id").Value, 16) == index).Select(i => i.Value).FirstOrDefault();
return result;
}
Result:
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.