473,387 Members | 1,497 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,387 software developers and data experts.

System.Xml.XmlException: Root element is missing.

getting an error as root element missing while reading and xml doucement


Expand|Select|Wrap|Line Numbers
  1.         string path = Server.MapPath("~/App_Data/use1.xml");
  2.         DataSet DS = new DataSet();
  3.         DataTable dt = new DataTable("Test");
  4.         dt.Columns.Add("totalvolume", typeof(string));
  5.         dt.Columns.Add("totalvalue", typeof(string));
  6.         dt.Columns.Add("totaloi", typeof(string));
  7.         dt.Columns.Add("totaltrades", typeof(string));
  8.         dt.Columns.Add("time", typeof(string));
  9.         DataRow dr = dt.NewRow();
  10.         dr["totalvolume"] = "";
  11.         dr["totalvalue"] = "";
  12.         dr["totaloi"] = "";
  13.         dr["totaltrades"] = "";
  14.         dr["time"] = "";
  15.  
  16.         dt.Rows.Add(dr);
  17.         System.IO.MemoryStream ms = new System.IO.MemoryStream();
  18.         dt.WriteXml(ms, XmlWriteMode.WriteSchema);
  19.         //Note: If you don't Seek back to the beginning, you will start your next read from the end of the stream
  20.         ms.Seek(0, System.IO.SeekOrigin.Begin);
  21.  
  22.         DataTable dt2 = new DataTable();
  23.         dt2.ReadXml(ms);
  24.         dt2.ReadXml(path);
  25.  
  26.  
  27.  
  28.         for (int i = 0; i < dt2.Rows.Count; i++)
  29.         {
  30.             AuthorLiteral.Text = Convert.ToString(dt2.Rows[i]["totalvolume"]);
  31.             TitleLiteral.Text = Convert.ToString(dt2.Rows[i]["totalvalue"]);
  32.             BodyLiteral.Text = Convert.ToString(dt2.Rows[i]["totaloi"]);
  33.             Literal1.Text = Convert.ToString(dt2.Rows[i]["totaltrades"]);
  34.             Literal2.Text = Convert.ToString(dt2.Rows[i]["time"]);
  35.  
  36.         }
Mar 7 '11 #1
0 1700

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Koji Ishii | last post by:
I'm trying to read response from a web server using XmlTextReader. Here's a code snippet. WebResponse rs = this.WebRequest.GetResponse(); Stream stm = rs.GetResponseStream(); XmlTextReader...
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...
3
by: Samem N via DotNetMonster.com | last post by:
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...
0
by: Frederico Guimar?es via DotNetMonster.com | last post by:
Hi, I'm trying to use the Microsoft.Web.Services2.Messaging. ISoapFormatter but I receive this error: System.Xml.XmlException: The root element is missing. at System.Xml.XmlTextReader.Read()...
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...
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...
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...
1
by: hvs69 | last post by:
I am writing a little application in c# which requires application of XSL transform on a RSS feed from YouTube. Here is the relevant code HttpWebRequest myreq =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.