473,320 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

The root element is missing

Does anyone know how to solve this error? I dont know where it went wrong.
Any help would be appreciated .Thanks

ERROR
______

Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.Xml.XmlException: The root element is missing.

Source Error:
Line 81: // Load the xml file
Line 82: XmlDocument xmldoc = new XmlDocument();
Line 83: xmldoc.Load( Server.MapPath("guestbook.xml"));
Line 84:
Line 85: //Create a new guest element and add it to the root node
Source File: e:\year 3\rhythm\rhythm_fyp\postcomments.aspx.cs Line: 83

Stack Trace:
[XmlException: The root element is missing.]
System.Xml.XmlTextReader.Read() +876
System.Xml.XmlValidatingReader.ReadWithCollectText Token()
System.Xml.XmlValidatingReader.Read()
System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean
preserveWhitespace) +80
System.Xml.XmlDocument.Load(XmlReader reader) +72
System.Xml.XmlDocument.Load(String filename)
Rhythm_Fyp.PostComments.SaveXMLData() in e:\year 3\rhythm\rhythm_fyp\
postcomments.aspx.cs:83
Rhythm_Fyp.PostComments.btnPost_Click(Object sender, EventArgs e) in e:\
year 3\rhythm\rhythm_fyp\postcomments.aspx.cs:71
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.
RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl,
String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
System.Web.UI.Page.ProcessRequestMain()
Nov 12 '05 #1
3 16229
Hello!
Exception Details: System.Xml.XmlException: The root element is missing.

XmlDocument xmldoc = new XmlDocument();
xmldoc.Load( Server.MapPath("guestbook.xml"));


Well, it seems your guestbook.xml is invalid - maybe you could post it
here? Change the code to this:

XmlDocument xmldoc = new XmlDocument();
string filename = Server.MapPath("guestbook.xml");
Trace.Write( filename );
xmldoc.Load( filename );

Does the file really exist? Does it contain any elements? Did you create
it by concatting multiple XML-Files?
--
Pascal Schmitt
Nov 12 '05 #2
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.N...-In-ASP.NET/1/

--
Message posted via http://www.dotnetmonster.com
Nov 12 '05 #3
Hello!
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?


You have to create the guestbook.xml file yourself, I think this should
work:

<?xml version="1.0" ?>
<guestbook>
</guestbook>
--
Pascal Schmitt
Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: David B. Bitton | last post by:
I am having a problem deserializing XML when the root node is missing a namespace declaration. My Type has an XmlTypeAttribute with a namespace defined. If I attempt to deserialize the XML, I get...
4
by: Cheryl Gilbert | last post by:
I'm sending xml to a web service by building a string dynamically. When my web service tries to validate the xml with a schema, I'm getting the error "the root element is missing". If I use an xml...
5
by: Paul Nations | last post by:
I'm in a real pickle. I've inherited a project with major problems. It receives encrypted XML files from a website not under my control (so I can't modify the web app) for insertion into a...
2
by: cordata5 | last post by:
Hi I'm using the example posted on Ron Howard's site for encryting the body of an xml file located at http://www.gotdotnet.com/team/rhoward/ I'm running into trouble where i'm getting an error of...
9
by: MR | last post by:
I get the following Exception "The data at the root level is invalid. Line 1, position 642" whenever I try to deserialize an incoming SOAP message. The incoming message is formed well and its...
2
by: Scott Emick | last post by:
I am still having issues with getting Root Element Missing instead of the actual error that the webservice call is supposed to be returning. I'm using VB .Net 2003. Has anyone else been able to...
1
by: Tomas | last post by:
When I try to load my xslt i get an xml exception with the message "Root element is missing". The stylesheet works when I preview it in stylus studio, but apparently not in my application. Any...
0
by: Dave Hill | last post by:
Forgive a newbie question. I'm learning the .NET XML environment. In the walkthrough on using XML designer to create an xsd, there is no discussion of the root element of the target xml document....
3
by: lisa.bogart | last post by:
I am getting a "Root element is missing" error when I try to load a stream into and XmlDocument. Can anyone help me with what I am doing wrong??? Dim xmlTextWriter As XmlTextWriter = Nothing...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.