The root element is missing when binding dataset to xml textreader

Hi,

I am attempting to create a xml file to a memory stream the bind it to a
dataset.  I can write a physical file with no problem.  However I recieve
the following error when trying to bind it to a dataset:

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

Here is my code:

MemoryStream ms = new MemoryStream();
XmlTextWriter xmlWriter = new XmlTextWriter(ms, Encoding.UTF8);

xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement("menu");
xmlWriter.WriteStartElement("menuItem");
xmlWriter.WriteElementString("text", "NewArticles");
xmlWriter.WriteEndElement();
xmlWriter.WriteEndElement();
xmlWriter.WriteEndDocument();
xmlWriter.Flush();
ms.Position = 0;

XmlTextReader xxx = new XmlTextReader(ms);
DataSet ds = new DataSet();

ds.ReadXml(xxx); <------------- Error here

ms.Close();
Menu1.DataSource = ds;
Menu1.DataBind();

Source Error:

Line 43:
Line 44: 			DataSet ds = new DataSet();
Line 45: 			ds.ReadXml(xxx);
Line 46: 			ms.Close();
Line 47:

Source File: c:\inetpub\wwwroot\ipass\header.ascx.cs    Line: 45

Stack Trace:

[XmlException: The root element is missing.]
   System.Xml.XmlTextReader.Read() +876
   System.Xml.XmlReader.MoveToContent() +75
   System.Data.DataSet.ReadXml(XmlReader reader, Boolean denyResolving)
   System.Data.DataSet.ReadXml(XmlReader reader)
   iPass.header.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\ipass\header.ascx.cs:45
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Control.LoadRecursive() +98
   System.Web.UI.Control.LoadRecursive() +98
   System.Web.UI.Page.ProcessRequestMain() +731




0
11/10/2003 4:44:13 PM
dotnet.xml 7266 articles. 0 followers. Follow

1 Replies
957 Views

Similar Articles

[PageSpeed] 5

Tulio Quinones wrote:

> I am attempting to create a xml file to a memory stream the bind it to a
> dataset.  I can write a physical file with no problem.  However I recieve
> the following error when trying to bind it to a dataset:
> 
> Exception Details: System.Xml.XmlException: The root element is missing.
> 
> Here is my code:
> 
> MemoryStream ms = new MemoryStream();
> XmlTextWriter xmlWriter = new XmlTextWriter(ms, Encoding.UTF8);
> 
> xmlWriter.WriteStartDocument();
> xmlWriter.WriteStartElement("menu");
> xmlWriter.WriteStartElement("menuItem");
> xmlWriter.WriteElementString("text", "NewArticles");
> xmlWriter.WriteEndElement();
> xmlWriter.WriteEndElement();
> xmlWriter.WriteEndDocument();
> xmlWriter.Flush();
> ms.Position = 0;
> 
> XmlTextReader xxx = new XmlTextReader(ms);
> DataSet ds = new DataSet();
> 
> ds.ReadXml(xxx); <------------- Error here

I cannot reproduce the problem, works for me.

-- 
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

0
Oleg
11/11/2003 11:46:10 AM
Reply:

Similar Artilces:

Help with using SDK XML to update entities
Hi, I have noticed a problem, in that when I try to use an Update or Create method, for example with the CRMEmail entity, I need to send the data in XML format, as set out in the entity's schema. However, for fields like emailbody, i need to pass HTML text to retain formatting. However, I can't include HTML markup without the XML parser spitting the dummy. I've tried escaping the special characters, (CleanXML = RawXML.Replace("<", "&#38;#60;") etc..), but the the database just stores and retrieves the escaped characters, rather than storing the origin...

XSD Validation error: "The element 'x...' cannot contain text"
Hi, I'm trying to validate an XML document against an XSD schema and I receive the following error: ---------- MyCode.CreateValidRequest : System.Web.Services.Protocols.SoapException : Validation error: The element 'http://xmlns.somewhere.com/something:rDetail' cannot contain text. Expected 'http://xmlns.somewhere.com/something:AList'. An error occurred at , (1, 533). ---------- There doesn't seem to be much information about this error - could anyone please help? I've included the schema fragment and sample XML below. Thanks, Bill --------------- ---- XSD ...

Missing email #8
I am currently trying to change from Netscape Mail (which I have loved using for years) to Outlook XP 2002. While I am experimenting, I have made Outlook my default email but also check Netscape for incoming mail, to make sure Outlook is receiving properly. Well, it isn't. I find important emails that come into my Netscape box (which I have changed so it is no longer my default) that never arrive in my Outlook box. This makes me fearful of changing over completely, as I believe I will be missing emails. Am I doing something wrong? Thank you. JWD wrote: > I am currently trying to...

HELP
It is possible to go directly for one definitive Node using XPath without having that to make one while in the XmlTextReader class? With a XmlNode class I know that possible, but my boubt is with a XmlTextReader class. If possible, please give me an example. Posted Via Usenet.com Premium Usenet Newsgroup Services ---------------------------------------------------------- ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY ** ---------------------------------------------------------- http://www.usenet.com NTC wrote: > It is possible to go directly for one d...

Invalid root in registry key ...
I'm a noobie at scripting, but I'm going through a self paced learning guide and one of the scripts calls some very basic information from the registry using RegRead. It seems that any reg value that I try to read from "HKCU\Volatile Environment\" fails. An example of the error I receive: WshShell.RegRead: Invalid root in registry key "HKCU\Volatile Environment\LOGONSERVER" or WshShell.RegRead: Invalid root in registry key "HKCU\Volatile Environment\USERNAME" or WshShell.RegRead: Invalid root in registry key "HKCU\Volatile Env...

XML schemas .NET 2.0
I have an XML schema and I am trying to validate any XML document sent against it. Here's some of the code: XmlReaderSettings xmlReaderSettings = new XmlReaderSettings(); xmlReaderSettings.Schemas.Add(@"http://myschema/myschema.xsd", "myschema.xsd"); xmlReaderSettings.ValidationEventHandler += new ValidationEventHandler(ValidationEvent); xmlReaderSettings.ValidationType = ValidationType.Schema; xmlReaderSettings.ValidationFlags = xmlReaderSettings.ValidationFlags | XmlSchemaValidationFlags.ReportValidationWarnings; ...

Identify missing numbers
I have a table that uses a text field to store receipt numbers. Currently I use VAL to sort the numbers numerically. Is there a way to identify which numbers are missing out of the sequence? For instance if my receipts start at 1 and go through 10,000, but receipts 900 through 987 are missing, can I get a query to show me that? Thanks! Tara By "missing" I asssume you mean "should be in a list but is not"... One way to do this is to have a list of what numbers SHOULD be listed, then use the query wizard to construct an "unmatched" query betw...

FRx Forecaster XML Export
I am trying to export a budget to a zipped XML file. The export wizard states that everything worked, but the zip file does not exist in the webdir directory or anywhere else. One discrepancy from the help file that I noticed is the absence of export check boxes for the fields in step two of the wizard. Any help would be appreciated. Thx, Matt. ...

missing icons in xp
Hi All, My wife is using windows xp home xr3. For some reason under programs under start menu she is missing standard icons such as startup accessories and the like. When I go to all users under documents and settings the icons show up. Can I fix this? Any help would be most appreciated. Thanks as allways. -- Regards, Gary Metzler send to: gmtravel@bellsouth.net http://www.outtasighttravel.com Msn messenger: gmetzler1150@hotmail.com Skype name: garymetz Gary, try this fix. http://www.raymond.cc/blog/archives/2008/05/11/restore-or-fix-missing-access...

Which is the root element
Hi; I have an xsd that has: <xsd:element name="purchaseOrder" type="PurchaseOrderType"/> <xsd:element name="comment" type="xsd:string"/> I get this as an XmlSchema using: XmlSchema schema = XmlSchema.Read(new FileStream(datasource.SchemaUrl, FileMode.Open, FileAccess.Read, FileShare.Read), null); schema.Compile(null); Two questions: 1) Is this the best way to get the schema? I am getting a warning that I should put it in an XmlSchemaSet and compile the set although this is my only schema. 2) The <purchaseOrder> element is the ...

Missing Text on Reply or Forward
When replying to or forwarding a message, some text from the original message is deleted and the signature lines have extra line feeds. ...

Missing color
I can color different columns and/or rows in Excel, and they will print; however I cannot see them on my monitor. I have to print the sheet to see what I've colored/highlighted. If the high contrast setting is turned on you won't see the fill colour. There's information in the following MSKB article: OFF: Changes to Fill Colour and Fill Pattern Are Not Displayed http://support.microsoft.com/?id=320531 SKHlandman wrote: > I can color different columns and/or rows in Excel, and they will print; > however I cannot see them on my monitor. I have to print the sheet to ...

square root function in excel (roots greater than 12)
Hello, I am currently undertaking some statistical analysis in excel but have encountered a data problem, my data is annual, and i need it monthly, hence need to take the 12th root of the numbers, but this doesnt seem available in excel, can you please advise kind regards How about: =YourNumber^(1/12) or =POWER(YourNumber,1/12) tj "Mark" wrote: > Hello, > > I am currently undertaking some statistical analysis in excel but have > encountered a data problem, my data is annual, and i need it monthly, hence > need to take the 12th root of the numbers, but t...

Determining elements that make up sum from a list
I have a list of data. This is a clearing account that does not clear. Total of this account is +90K and change. I need to know what numbers make up that total from the list of all transactons that have come through this month. Reverse engineering for sums. See: http://www.tushar-mehta.com/excel/templates/match_values/index.html -- Gary''s Student - gsnu200909 "michaelcooper" wrote: > I have a list of data. This is a clearing account that does not clear. > Total of this account is +90K and change. I need to know what numbers make > ...

ASP.NET Server controls application root operator resolves to server root
Hi there I am a web developer, and I have web hosting with GoDaddy that allows the multiple websites/domains I develop to be hosted with them. I can also use it for subdomains of my own domain name to preview work to clients before it is live. An annoying issue I'm experiencing regarding subdomains of my domain name is that I've setup virtual directory / application roots in subfolders of my web server in my hosting account, and I point the subdomain to the IP of the server, and whilst this works, any use of the application root operator / tilde (~) resolves to a URL inclu...

Define element of XSD as an element in another XSD file
I'm new to hand-coding XSD files - how can I indicate that I want to reference tags from another XSD document in a certain section of my XSD? Essentially, I want to define one XSD with some elements and in another XSD define an area that allows elements from the first XSD. Thanks in Advance, Richard Richard A. Lowe wrote: > I'm new to hand-coding XSD files - how can I indicate that I want to > reference tags from another XSD document in a certain section of my > XSD? Essentially, I want to define one XSD with some elements and in > another XSD define an area that allow...

[ANN] eXml
I'm glad to announce first release of the eXml - extended ASP.NET Xml Web Server Control. eXml is a free open-source ASP.NET 2.0 Web server control extending and improving standard ASP.NET XML Web server control. eXml Web server control uses new .NET 2.0 XSLT processor - XslCompiledTransform class to perform XSL transformations thus providing in average 400% performance boost and improved standard compliance. Additionally eXml Web server control provides built-in support for 70+ EXSLT extension functions, XML Inclusions (XInclude) 1.0, friendly XML rendering, <?xml-stylesheet?> XML ...

How to setup root path in CFileDialog
Hi All, Please let me know how to setup initial root path in Open/Save as common dialog boxes created through CFileDialog. TIA Vasis >Please let me know how to setup initial root path in Open/Save as >common dialog boxes created through CFileDialog. See the documentation on the lpstrInitialDir member of the OPENFILENAME structure (which is the m_ofn member of the CFileDialog). Dave David Lowndes wrote: >>Please let me know how to setup initial root path in Open/Save as >>common dialog boxes created through CFileDialog. > > > See the documentation on the ...

"Field Level Security" is missing in GP9
We are on GP9 (Advanced Management version). Field Level Security does not appear in the Tools > Setup > System menu. It *does* appear in the Tools > System > Setup > Advanced Security > By Menu section, and it *is* checked for the appropriate users. Is this something that needs to be installed or is there a problem with the current installation? How can I guess this to appear so that I can use it? Thank you for your help. Justin Field Level Security is part of the Advanced Security chunk. So it is installed. If there is a problem with the tables it might preven...

rules wizard missing
Hi, I just got a new computer (win xp) and I just moved all my pst's and stuff from my old computer to my new one. I have all my messages and folders. However under Tools, there is no rules wizard option. I tried to do a repair install and see there was a wizard or other feature that was marked install at run or whatever, instead of just install to disk but I didn't notice it. How do I add the rules wizard to outlook 2002? Never mind, even though I transferred my psts and other files, I hadn't setup an email account yet. After I setup the account Rules Wizard...

Hiding graphics elements?
How can we hide pre-selected groups of graphics elements with the touch of a cell or control? We have two distinct groups of rectangles with gradient fills. Depending on the state (true/false) of a control, we want one or the other group of rectangles to be hidden while the other is displayed. Can anyone give us some direction on how we might accomplish this? Unlike controls, we don't see where rectangles have a property for visibility or for hiding the object. Let's say one of your rectangles is named "Rectangle 1", then you can hide it like this... ...

Missing font in MS Publisher
When I go to use the Palatino font in MS Publisher 2007, it says it is missing. I like it. How can I get it into the program? Thanks, Tom Palatino shipped with Office Pro 2003, Windows 2000, Windows XP -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "Thomas Minter" <tminter5@adelphia.net> wrote in message news:47826b11$0$28818$4c368faf@roadrunner.com... > When I go to use the Palatino font in MS Publisher 2007, it > says it is missing. I like it. How can I get it into the program? > > Thanks, > Tom ...

Missing email
Sometimes when I press "sync", I see on the bottom of the screen "1 new message", but that message never shows up in my all inbox folder. Is the email lost? Is this a bug? Did you look in your Junk E-mail folder and Deleted Items folder? --=20 Gary VanderMolen, Microsoft MVP (Mail) Microsoft MVP Program: http://mvp.support.microsoft.com "boss man" <boss man@discussions.microsoft.com> wrote in message = news:20EA3246-8995-42A9-A9EB-354B87049079@microsoft.com... > Sometimes when I press "sync", I see on the bottom of the screen &...

MDX query be persistence in an XML format
Hello Gurus, Need your help on following: 1. Whether an MDX query be stored in an XML format? e.g. can the below query be stored in an XML file format: (the query is for illustration only). with set [PromoMonths] as 'Filter([Time].[Month].Members, Not IsEmpty( ([Unit Sales], [Double Your Savings]) ) )' set [PromoRange] as 'Head( [PromoMonths] ).item(0).item(0) : Tail( [PromoMonths] ).item(0).item(0)' member [Measures].[Uplift] as '([Unit Sales], [Double Your Savings])' member [Measures].[This Quarter] as '[Unit Sales]' member [Measures].[Last Quarter] ...

Root Business Unit
Hey everyone, Is there any way to change the name of the root business unit? Thanks! -Gus nope. another work around is to redeploy your organization and rename the database to your newly desired organization. "Gus" <gwelter@gmail.com> wrote in message news:559a3c47-874a-41a6-b0d9-8914f91d9275@q78g2000hsh.googlegroups.com... > Hey everyone, > > Is there any way to change the name of the root business unit? > > Thanks! > > -Gus You can change it in the database directly, BusinessUnitBase Usual terms and conditions apply "Gus" <gwelte...