I've searched but couldn't find anything similar as this is probably very basic. I'm basically trying to read a list of movies from an xml file and then to pass it back into a Model for various types of consumption. But I get a "System.NullReferenceException: Object reference not set to an instance of an object." My (sudo) c# code looks something like this
var xmlDoc = new XmlDocument();
xmlDoc.Load("c:\\movies.xml");
var movieModel = new MovieSummary();
var MovieXML = xmlDoc.GetElementsByTagName("movie");
int i;
for (i = 0; i < MovieXML.Count; i++)
{
movieModel.Movies[i].name = MovieXML[i]["name"].toString();
}
my Model looks like this
namespace movies.Models
{
public class MovieSummary
{
public List<Movie> Movies { get; set; }
}
public class Movie
{
public string movie { get; set; }
}
}
xml file looks like
<movies xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<movie>
<name>The Dark Knight</name>
</movie>
<movie>
<name>Iron Man</name>
</movie>
</movies>