Click here to Skip to main content
15,849,996 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I am getting this error when I am trying to load an
xml file:

Data at the root level is invalid. Line 1, position 1.

This is my code I used:

XmlDocument SAP_SettingsXML = new XmlDocument();

            XmlNode node = SAP_SettingsXML.CreateNode(XmlNodeType.Element, "OutboundPath", null);
            node.InnerText = txt_DirectoryPath.Text;

            //add to elements collection


Here is my xml File content:

<?xml version="1.0" encoding="utf-8"?>
<Inbound_Path xmlns=" ">C:\Users\Ben\Desktop</Inbound_Path><

Please any help would be appriciated!!
Updated 11-May-12 3:38am

Data at the root level is invalid. Line 1, position 1.
See if your XML file is properly formed. Make sure there is no space or new line at the top before the root tag.
Share this answer
Sergey Alexandrovich Kryukov 11-May-12 12:28pm    
My 5. However, there is an error (now well-formed XML) in the shown code -- please see my answer.
Sandeep Mewara 11-May-12 13:08pm    
Thanks SA.
Wendelius 11-May-12 14:05pm    
Good answer with information given at the time.
Sandeep Mewara 12-May-12 1:45am    
Thanks Mika.
Your XML is not well-formed, but perhaps you just poorly formatted it in HTML while formulating the question. The error is in last two lines: there must not be a new line delimiter between them, as you break '<' and '/'.

Share this answer
Sandeep Mewara 11-May-12 13:08pm    
When I replied, there was no XML SA, OP just posted the error with code used.
Sergey Alexandrovich Kryukov 11-May-12 13:51pm    
Sure, not a problem. After all, I voted 5; if you answered that way not seeing XML, it only adds the value to your answer.
Thank you, Sandeep.
Sergey Alexandrovich Kryukov 11-May-12 13:52pm    
And thanks for the comment as I did not see that my own answer was malformatted -- fixed now :-).
Wendelius 11-May-12 14:05pm    
Looks right :)
Sergey Alexandrovich Kryukov 11-May-12 16:31pm    
Thank you, Mika.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900