- Joined
- Oct 24, 2012
- Messages
- 6,545
Im 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.
Here is what i am trying to do.
Can anyone tell me where my problem is ? thanks.
The error i keep getting is this.
Note: I do have the required using System directives.
Found the problem.
Here is what my xml file looks like.
Code:
<?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.
Code:
try
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(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);
}
}
The error i keep getting is this.
Data at the root level is invalid. Line 1, position 1.
Note: I do have the required using System directives.
Found the problem.
Code:
try
{
XmlDocument doc = new XmlDocument();
doc.Load(movieListXML);
XmlNode node = doc.SelectSingleNode("/MovieData");
foreach (XmlNode movie in node.SelectNodes("Movie"))
{
if (movie != null)
{
movieTypeListBox.Items.Add(movie["Name"].InnerText);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
Last edited: