C# – Very Basic XML Parsing

In my app I have a VERY basic XML file with a list of countries & country codes. It looks like this;


Parsing this is very simple.
Using System.Xml;

XmlDocument xml = new XmlDocument();
XmlNodeList nodes = xml.SelectNodes("/xml/item");
foreach(XmlNode node in nodes) {
    Console.WriteLine(node["code"].InnerText + " = " + node["country"].InnerText);

Maybe you can use this as the basis for an RSS reader (although I’m sure there are better alternatives) .  I use it just to populate a drop-down box & convert from the country code to name.

One Response to “C# – Very Basic XML Parsing”

  1. […] Simple XML parsing – I use this to convert between county names & country codes […]

Leave a Reply