I'm trying to load data from the nodes in my xml file to get them to post in a listbox. Here is what my xml file looks like.
<?xml version="1.0" encoding="utf-8"?>
<MovieData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Movie>
<Name>Death Race</Name>
<Type>Action</Type>
<Type>Adventure</Type>
<Rating>R</Rating>
<Disk>Blu-Ray</Disk>
</Movie>
<Movie>
<Name>Death Race 2</Name>
<Type>Action</Type>
<Type>Adventure</Type>
<Rating>R</Rating>
<Disk>Blu-Ray</Disk>
</Movie>
</MovieData>
Here is what i am trying to do.
try
{
XmlDocument doc = new XmlDocument();
doc.Load(movieListXML);
XmlNodeList nodeList = doc.SelectNodes("/MovieData");
foreach (XmlNode xn in nodeList)
{
XmlNode movie = xn.SelectSingleNode("Movie");
if (movie != null)
{
movieTypeListBox.Items.Add(movie["Name"].InnerText);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
Can anyone tell me where my problem is ? thanks.