Again, its says " The root element is missing"
I took this code from the net, but it doesnt seem to work for me. The XML
file has not been created and no elements are inside.
How do u think i can solve this?
Here's the original code
--------------------------------
01: using System;
02: using System.Web;
03: using System.Web.UI;
04: using System.Web.UI.WebControls;
05: using System.Xml;
06: public class Guestbook : Page
07: {
08: // Create the required webcontrols with the same name as in the
guestbook.aspx 09: //file.
10: public TextBox name;
11: public TextBox location;
12: public TextBox email;
13: public TextBox website;
14: public TextBox comment;
15: public void Save_Comment(object sender, EventArgs e)
16: {
17: // Everything is all right, so let us save the data into the XML file
18: SaveXMLData();
19: // Remove the values of the textboxes
20: name.Text="";
21: location.Text="";
22: website.Text="";
23: email.Text="";
24: comment.Text="";
25: }
26: }
27: private void SaveXMLData()
28: {
29: // Load the xml file
30: XmlDocument xmldoc = new XmlDocument();
31: xmldoc.Load( Server.MapPath("guestbook.xml") );
32: //Create a new guest element and add it to the root node
33: XmlElement parentNode = xmldoc.CreateElement("guest");
34: xmldoc.DocumentElement.PrependChild(parentNode);
35: // Create the required nodes
36: XmlElement nameNode = xmldoc.CreateElement("name");
37: XmlElement locationNode = xmldoc.CreateElement("location");
38: XmlElement emailNode = xmldoc.CreateElement("email");
39: XmlElement websiteNode = xmldoc.CreateElement("website");
40: XmlElement commentNode = xmldoc.CreateElement("comment");
41: // retrieve the text
42: XmlText nameText = xmldoc.CreateTextNode(name.Text);
43: XmlText locationText = xmldoc.CreateTextNode(location.Text);
44: XmlText emailText = xmldoc.CreateTextNode(email.Text);
45: XmlText websiteText = xmldoc.CreateTextNode(website.Text);
46: XmlText commentText = xmldoc.CreateTextNode(comment.Text);
47: // append the nodes to the parentNode without the value
48: parentNode.AppendChild(nameNode);
49: parentNode.AppendChild(locationNode);
50: parentNode.AppendChild(emailNode);
51: parentNode.AppendChild(websiteNode);
52: parentNode.AppendChild(commentNode);
53: // save the value of the fields into the nodes
54: nameNode.AppendChild(nameText);
55: locationNode.AppendChild(locationText);
56: emailNode.AppendChild(emailText);
57: websiteNode.AppendChild(websiteText);
58: commentNode.AppendChild(commentText);
59: // Save to the XML file
60: xmldoc.Save( Server.MapPath("guestbook.xml") );
61: // Display the user the signed guestbook
62: Response.Redirect("viewguestbook.aspx");
63: }
64: }
Source :
http://www.devarticles.com/c/a/ASP.NET/Create-Your-Own-Guestbook-In-ASP.NET/1/
--