Hi everyone. I've got this code that I've been following along with a sample. However, whenever I debug it, I get the error 'XML Exception was unhandled: Root element is missing.' Here's the code I have so far.
namespace SpiveyPropertyRental
{
public partial class Tenants : Form
{
public Tenants()
{
InitializeComponent();
}
public void ShowTenants()
{
string strFileName = @"C:\Spivey Property Rental\tenants.xml";
XmlDocument docTenants = new XmlDocument();
if (File.Exists(strFileName))
{
lvwTenants.Items.Clear();
docTenants.Load(strFileName);
XmlElement elmTenant = docTenants.DocumentElement;
XmlNodeList lstTenants = elmTenant.ChildNodes;
foreach (XmlNode node in lstTenants)
{
ListViewItem lviTenant = new ListViewItem(node.FirstChild.InnerText); //Account #
lviTenant.SubItems.Add(node.FirstChild.NextSibling.InnerText); //Full Name
lviTenant.SubItems.Add(node.FirstChild.NextSibling.NextSibling.InnerText); //Phone #
lviTenant.SubItems.Add(node.FirstChild.NextSibling.NextSibling.NextSibling.InnerText); //Marital Status
lvwTenants.Items.Add(lviTenant);
}
}
}
private void Tenants_Load(object sender, EventArgs e)
{
ShowTenants();
}
}
}
I'm getting the exception here-
docTenants.Load(strFileName);