I have an XML document (without attributes) that is setup like this:
<variables>
<variable>
<name>Name_Value</name>
<value>Value of Entry</value>
</variable>
<variable>
<name>Name_Value2</name>
<value>Value of Entry2</value>
</variable>
</variables>
I have used LINQ to XML to get a list of all the <name> values in the document. These name values are displayed in a listbox control in alphabetical order (which is not the order of the names in the XML document).
When an item is selected in the listbox, I want to pass the name of the item to a method that will search the XML document for that value within the <name> node. Once found, I want to find the next node (i.e., the <value> node) and return it’s value as a string.
I’ve tried all sorts of things to get this information, but apparently I don’t know enough about LINQ to XML to get this work. Can only provide a solution for this?
This Linq query will return
IEnumerbale<string>of value elements, which matched your name. If you sure there should be no more than one variable with specified nameOr in single query: