C Board  

Go Back   C Board > General Programming Boards > C# Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 12-14-2007, 09:51 AM   #1
Registered User
 
Join Date: Nov 2005
Posts: 41
Arrow XmlException: The data at the root level is invalid. Line 1, position 1.

I have tried to fins anything about this on Internet, and do get some hits. However, I don't seem to be able to figure out what is wrong. Anyone that have an idea?

The data should be ok. It starts like:
<?xml version= ......



Code:
           System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();

            byte[] bytesin = encoding.GetBytes(msgin);
            ProtocolHeader protocolHdr = ProtocolHeader.ReadProtocolHeader(bytesin, 0, msgin.Length);

            MemoryStream hdrin = new MemoryStream(bytesin, Convert.ToInt16(protocolHdr.ProtocolHeaderSize), msgin.Length - Convert.ToInt16(protocolHdr.ProtocolHeaderSize));
            XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();
            xmlReaderSettings.IgnoreWhitespace = true;
            XmlReader msginReader = XmlReader.Create(hdrin, xmlReaderSettings);
            


            while (msginReader.Read())
            {
// ...
            }
mdoland is offline   Reply With Quote
Old 12-14-2007, 10:06 AM   #2
and the hat of Jobseeking
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,676
Perhaps it isn't an ASCII file at all, and it ran into this at the start of the file.
http://en.wikipedia.org/wiki/Byte_Order_Mark
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.

Salem is offline   Reply With Quote
Old 12-14-2007, 10:15 AM   #3
Registered User
 
Join Date: Nov 2005
Posts: 41
Hmm, slightly embarassed. I think I found the error. I started one character to late. I skipped the <.

Thank you anyway. Sometimes one just have to express the problem to realize what actually is the bug.
mdoland is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bitmasking Problem mike_g C++ Programming 13 11-08-2007 12:24 AM
Button handler Nephiroth Windows Programming 8 03-12-2006 06:23 AM
Templated Binary Tree... dear god... Nakeerb C++ Programming 15 01-17-2003 02:24 AM
Contest Results - May 27, 2002 ygfperson A Brief History of Cprogramming.com 18 06-18-2002 01:27 PM
Greenhand want help! leereg C Programming 6 01-29-2002 06:04 AM


All times are GMT -6. The time now is 01:13 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22