We store static data in an XML file with different groupings of data. The file is actually quite large and I’ve pared it down for this question. Each of these are a small subset of their data.
<?xml version="1.0" encoding="utf-8" ?>
<datasets>
<dataset id="USRegions">
<record code="SoCal">Southern California</record>
<record code="NoCal">Northen California</record>
</dataset>
<dataset id="Countries">
<record code="US" callingcode="1|US">United States</record>
<record code="CA" callingcode="1|CA">Canada</record>
<record code="GB" callingcode="44|GB">United Kingdom</record>
<record code="MX" callingcode="52|MX">Mexico</record>
</dataset>
</datasets>
For purposes of validation I want to make sure that the passed in country code, “US” for example, exists in the static data. I can get to the recordset with this query, but I’m stumped on how to drill deeper into the data.
var dataset = from record in _xAddressData.Descendants("dataset")
where (string) record.Attribute("id") == "Countries"
select record.DescendantNodes();
One approach:
Used like: