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

  1. #1
    Registered User
    Join Date
    Nov 2005

    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= ......

               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())
    // ...

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Perhaps it isn't an ASCII file at all, and it ran into this at the start of the file.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Nov 2005
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

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