all groups > dotnet xml > may 2004 >
You're in the

dotnet xml

group:

The data at the root level is invalid. Line 1, position 1


The data at the root level is invalid. Line 1, position 1 Deena
5/21/2004 2:04:44 AM
dotnet xml: I pulling my hair out with is error!

I've used an external source to validate my schema against
the xml and it succeeds without any errors
(http://apps.gotdotnet.com/xmltools/xsdvalidator/Default.as
px) but as soon as I run it through some code it pops up
with that error!

Here's my code:

// Create and setup XML
document
XmlTextWriter
xmlDiskWriter = new XmlTextWriter
(fullyQualifiedFilename,Encoding.UTF8);
xmlDiskWriter.Formatting =
Formatting.Indented; // For easier reading :)
xmlDiskWriter.Indentation
= 4; // Looks even nicer ...

xmlDiskWriter.WriteStartDocument();



// Transform
xslDoc.Transform
(xmlDoc,null,xmlDiskWriter,null);

// Validate CID
try
{

XmlReader xmlRead
= new XmlTextReader(location.ToOSString() + xsdCID);

XmlSchemaCollection xsdDoc = new
XmlSchemaCollection();

XmlValidatingReader xmlValid = new
XmlValidatingReader( xmlDiskWriter.ToString
(),XmlNodeType.Document, null);

xsdDoc.Add
(null,xmlRead);

xmlValid.Schemas.Add(xsdDoc);

// Add validation
event handler

xmlValid.ValidationType = ValidationType.Schema;

xmlValid.ValidationEventHandler += new
ValidationEventHandler(ValidationHandler);


xmlValid.MoveToContent();

while(xmlValid.Read
());
xmlValid.Close();

// Raise
exception, if XML validation fails
if (ErrorsCount >
0)
{
throw new
Exception(ErrorMessage);
}
}
catch(Exception error)
{
// XML Validation
failed
MessageBox.Show
("XML validation failed:" + error.Message, "Error",

MessageBoxButtons.OKCancel, MessageBoxIcon.Error);

}

Re: The data at the root level is invalid. Line 1, position 1 Don Wham
5/27/2004 3:42:27 AM

Got the same problem over here !

I have a IE Web Controls Treviewcontrol filled with an at runtim
generated XML (generated from a database.) In my developmen
environment all is working fine. But in a release environment i
crashes with this error. (See attachment bmp)

Anybody any idea's ?


TX,
Don Wha

+----------------------------------------------------------------
| Attachment filename: error.png
|Download attachment: http://www.mcse.ms/attachment.php?postid=1827686
+----------------------------------------------------------------

-
Don Wha
-----------------------------------------------------------------------
Posted via http://www.mcse.m
-----------------------------------------------------------------------
View this thread: http://www.mcse.ms/message698013.htm
Re: The data at the root level is invalid. Line 1, position 1 Oleg Tkachenko [MVP]
6/7/2004 10:32:26 AM
[quoted text, click to view]

Generally speaking the error means the XML is malformed. Usually that
happens when remote resource appears to be text, not XML, or there is
some text just before root element tag. Make sure you've got well-formed
XML.
PS. Can it be security issue?
--
Oleg Tkachenko [XML MVP]
AddThis Social Bookmark Button