I have the following XML file.
<?xml version="1.0" encoding="utf-8" ?>
<Countries>
<Country>
<Id>101</Id>
<City>Austin</City>
</Country>
<Country>
<Id>102</Id>
<City>Dallas</City>
</Country>
<Country>
<Id>103</Id>
<City>Chicago</City>
</Country>
<Country>
<Id>104</Id>
<City>Aman</City>
</Country>
</Countries>
I am trying to read it from code behind. Here is the code
List<City> cityList = new List<City>();
string url = "/App_Data/Countries.xml";
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath(url));
XmlNodeList nodeList = doc.SelectNodes("Country");
foreach (XmlNode node in nodeList)
{
if (node != null)
{
int id = int.Parse(node.Attributes["Country"].Value);
string name = node.Attributes["City"].Value;
City city = new City(id, name);
cityList.Add(city);
}
}
For some reason, the code below
XmlNodeList nodeList = doc.SelectNodes("Country");
returns no nodes at all.