.NETGURU
XMLException
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngxml' list.


SNegussie@aol.com
Hi,

I get the following XML exception:

[XmlException: There is invalid data at the root level. Line 1, position 1.]

Any ideas why?
Reply to this message...
 
    
TomMallard
Where's the code?

Bet you didn't define the root...

tom mallard
seattle
-----Original Message-----
From: Click here to reveal e-mail address [mailto:Click here to reveal e-mail address]
Sent: Saturday, June 29, 2002 3:49 PM
To: aspngxml
Subject: [aspngxml] XMLException

Hi,

I get the following XML exception:

[XmlException: There is invalid data at the root level. Line 1, position
1.]

Any ideas why? | [aspngxml] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngxml.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives
Reply to this message...
 
    
SNegussie@aol.com
The root is defined. I'm using XMLTextWriter to build the XML file. Here's
the part of the code that I believe is relevant to this discussion:

HttpContext current;
current = HttpContext.Current;
current.Response.ContentType = "text/xml";
current.Response.ContentEncoding = new System.Text.UTF8Encoding();

TextWriter outputWriter = current.Response.Output;
XmlTextWriter writer = new XmlTextWriter(outputWriter);

int leftnode, rightnode;

writer.Formatting = Formatting.Indented;

//Use XMLTextWriter to build the tree
writer.WriteStartDocument();
writer.WriteStartElement("TREENODES");

writer.WriteStartElement("TreeNode");
writer.WriteAttributeString("id", "activity" +
rlevelone["activity_id"].ToString());
writer.WriteAttributeString("Text", "<U>" +
rlevelone["Name"].ToString() + "</U>");

writer.WriteAttributeString("NavigateUrl",destinationUrl.ToString()+rlevelone[

"activity_id"].ToString());
writer.WriteEndElement();

writer.WriteEndDocument();
writer.Close();
Reply to this message...
 
    
TomMallard
Why do you declare the start element twice?

writer.WriteStartElement("TREENODES");

writer.WriteStartElement("TreeNode");

tom
-----Original Message-----
From: Click here to reveal e-mail address [mailto:Click here to reveal e-mail address]
Sent: Sunday, June 30, 2002 12:48 PM
To: aspngxml
Subject: [aspngxml] RE: XMLException

The root is defined. I'm using XMLTextWriter to build the XML file.
Here's the part of the code that I believe is relevant to this discussion:

HttpContext current;
current = HttpContext.Current;
current.Response.ContentType = "text/xml";
current.Response.ContentEncoding = new System.Text.UTF8Encoding();

TextWriter outputWriter = current.Response.Output;
XmlTextWriter writer = new XmlTextWriter(outputWriter);

int leftnode, rightnode;

writer.Formatting = Formatting.Indented;

//Use XMLTextWriter to build the tree
writer.WriteStartDocument();
writer.WriteStartElement("TREENODES");

writer.WriteStartElement("TreeNode");
writer.WriteAttributeString("id", "activity" +
rlevelone["activity_id"].ToString());
writer.WriteAttributeString("Text", "<U>" + rlevelone["Name"].ToString() +
"</U>");

writer.WriteAttributeString("NavigateUrl",destinationUrl.ToString()+rlevelon
e["activity_id"].ToString());
writer.WriteEndElement();

writer.WriteEndDocument();
writer.Close(); | [aspngxml] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngxml.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives
Reply to this message...
 
    
Kirk Allen Evans
Is it possible that rlevelone["activityid"] is null?

Here is a watered-down version of the code that works. Does this sample
code run without error? If so, then start adding a little bit more of your
code in (like rlevelone and the NavigateURL) to see if any of those are
actually causing the error indirectly.

Your sample code does not have a matching number of WriteStartElement and
WriteEndElement calls, but the WriteEndDocument call should close any open
Element tags. The only other additions I made were directly using the
Reponse.Output property in the ctor to XmlTextWriter, and added a call to
the XmlTextWriter's Flush method to commit the changes to the underlying
stream prior to closing the writer. These changes should be mostly
cosmetic, though, and have no bearing on the XmlException that you are
receiving. This should at least help you pinpoint more closely what is
happening.

private void Page_Load(object sender, System.EventArgs e)
{
HttpContext current;
current = HttpContext.Current;
current.Response.ContentType = "text/xml";
current.Response.ContentEncoding = new System.Text.UTF8Encoding();

XmlTextWriter writer = new XmlTextWriter(current.Response.Output);

writer.Formatting = Formatting.Indented;

//Use XMLTextWriter to build the tree
writer.WriteStartDocument();
writer.WriteStartElement("TREENODES");

writer.WriteStartElement("TreeNode");
writer.WriteAttributeString("id", "activity1");
writer.WriteAttributeString("Text", "<U>test</U>");

writer.WriteAttributeString("NavigateUrl","http://www.test.com";);
writer.WriteEndElement();

writer.WriteEndDocument();
writer.Flush();
writer.Close();
}

Kirk Allen Evans
http://www.xmlandasp.net
"XML and ASP.NET", New Riders Publishing
http://www.amazon.com/exec/obidos/ASIN/073571200X

Reply to this message...
 
    
SNegussie@aol.com
I found out what the problem was. It had to do with the data that was
returned. One of the filters I was using was not correct.

Thanks
S
Reply to this message...
 
 
System.EventArgs
System.IO.TextWriter
System.Text.UTF8Encoding
System.Web.HttpContext
System.Windows.Forms.TreeNode
System.Xml.Formatting
System.Xml.XmlException
System.Xml.XmlTextWriter




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification