I have a big ton of xml-data with a lot of properties and I want to parse the values out of the xml-lines that contain specific properties. This is the xml data:
<Root xmlns:wb="http://www.worldbank.org">
<data>
<record>
<field name="Country or Area" key="ABW">Aruba</field>
<field name="Item" key="SP.URB.TOTL.IN.ZS">Urban population (% of total)</field>
<field name="Year">1960</field>
<field name="Value">50.776</field>
</record>
</data>
</Root>
I would like to get Aruba, 1960 and 50.776 out of this.
I've tried this:
XmlDocument xml = new XmlDocument();
xml.Load("daten.xml");
XmlNodeList list = xml.SelectNodes("//data/record/field");
foreach (XmlNode item in list)
{
Console.WriteLine(item.Attributes["Name"].Value);
}
This one throws an exception, but I tried also other ways with item["field"] or item["field@[name='Year']], but nothing worked out for me.