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

This is a discussion on XmlException: The data at the root level is invalid. Line 1, position 1. within the C# Programming forums, part of the General Programming Boards category; I have tried to fins anything about this on Internet, and do get some hits. However, I don't seem to ...

  1. #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())
                {
    // ...
                }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,761
    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.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #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.

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 Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 02:27 PM
  5. Greenhand want help!
    By leereg in forum C Programming
    Replies: 6
    Last Post: 01-29-2002, 06:04 AM

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