Would like to ask some advice when working with xml data with C#. I have a small practice exercise where I am required to retrieve a specific text value at a specific tag.
I have assigned the various names of the element nodes to string values and the the user is required to input a string value to the console and if the name tag is the same as the input then to retrieve the text value positioned at that tag. This is the C# code I used but I am not sure how to retrieve the text value at the name tag.
int priceSpecific;
string destination;
ArrayList array = new ArrayList();
xRootNode = xdoc.DocumentElement;
string firstValue = xRootNode.FirstChild.FirstChild.Name;
string secondValue = xRootNode.FirstChild.FirstChild.NextSibling.Name;
string thirdValue = xRootNode.FirstChild.FirstChild.NextSibling.NextSibling.Name;
string fourthValue = xRootNode.FirstChild.FirstChild.NextSibling.NextSibling.NextSibling.Name;
array.AddRange(new object[] { firstValue, secondValue, thirdValue, fourthValue});
Console.WriteLine("Please enter your destination, first letter capital");
destination = Console.ReadLine();
The idea is to loop through the arraylist and retrieve the name of the element node that is the same as the string input of the user. Any advice as to how to retrieve the text value?
Regards