AlexeWarr
Epic Member
Hello, I'm trying to write to an xml file to save a folder path location but Im getting an error "root element is missing".
I have marked where the error is from
I have marked where the error is from
Code:
private void wowpathbutton_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
wowpath.Text = folderBrowserDialog1.SelectedPath;
XmlDocument xml = new XmlDocument();
[B][U][COLOR="#FF0000"]xml.Load("save.xml");[/COLOR][/U][/B]
if (xml.ChildNodes.Count == 0) // if xml file is empty, write elements and save path
{
XmlElement newcatalogentry = xml.CreateElement("settings");
XmlElement firstelement = xml.CreateElement("WoWPath");
firstelement.InnerText = folderBrowserDialog1.SelectedPath;
newcatalogentry.AppendChild(firstelement);
xml.DocumentElement.InsertAfter(newcatalogentry, xml.DocumentElement.LastChild);
xml.Save("save.xml");
}
else // we save the wow path
{
XmlNodeList reminders = xml.SelectNodes("//settings");
foreach (XmlNode reminder in reminders)
{
reminder.SelectSingleNode("WoWPath").InnerText = folderBrowserDialog1.SelectedPath;
}
}
}
}