I had been reading various tutorials but couldn't figure out to conditionally parse the following XML structure, where user inputs name of a State and then receive the name of the Capitol.
When I test it with the following code, I get no MessageBox popped up.
C# code
XDocument xd = XDocument.Load("Foo.xml");
foreach (var state in xd.Descendants("State"))
{
Messagebox.Show(state.Attribute("Name").Value);
}
Foo.xml
<Main>
<Title></Title>
<Planet Name="Earth">
<Continent Name="North America">
<Country Name="USA">
<State Name="Illinois" Capital="Springfield"></State>
<State Name="Alabama" Capital="Montgomery"></State>
...
</Country>
<Country Name="Canada">
<State Name="Alberta" Capital="Edmonton"></State>
<State Name="British Columbia" Capital="Victoria"></State>
<State Name="Manitoba" Capital="Winnipeg"></State>
....
</Country>
<Country> ... </Country>
<Country> ... </Country>
<Country> ... </Country>
</Continent>
</Planet>
</Main>