Process short description: In the form, I will have a dropdown list with the countries from the XML file. Based on the selection from the form, I will want to extract the corresponding city.
What do I have currently? At the moment, I have a For Each cycle to run all the country elements and add it to a list. Then the Form appears with the countries dropbdown list and it saves the selected option into a variable (selectedOption). Based on the result, I am using another For Each cycle to check if the actual for each element equals the selected form option or not. This solution works fine.
Optimization suggestions: However, I would like to know if this is possible or how to do a query in XML . Something like:
FROM country in xmlFile.Element("root").Element("item").Element("country").Value WHERE xmlFile.Element("root").Element("item").Element("city").Value.Equals(selectedOption) SELECT country
I am not sure I understand the process completely…
But regarding the optimization:
I don’t know how to query to an XML-file. But if you do have the XML-file available I would use Regex to get it into a datatable [“Country | City”] and use datatable.select
You can try reading your xml to a Data Table and then will be easier to handle filters and everything… use myDataTable.ReadXml(“c:\myfile.xml”) after initializing an empty data table variable.
@bcorrea, yes that using a datatable also works. My question was regarding if it is possible to do something like a query with XML or not Thanks for your suggestion