Click here to Skip to main content
15,892,737 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:

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


This is my code I used:

C#
XmlDocument SAP_SettingsXML = new XmlDocument();
            SAP_SettingsXML.LoadXml(SAP_Manager.PublicVariables.clsPublicVariables.SettingsPath);

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

            //add to elements collection
            SAP_SettingsXML.DocumentElement.AppendChild(node);

            SAP_SettingsXML.Save(SAP_Manager.PublicVariables.clsPublicVariables.SettingsPath);


Here is my xml File content:

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


Please any help would be appriciated!!
Posted
Updated 11-May-12 2:38am
v2

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
 
Comments
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.
--SA
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 '/'.

—SA
 
Share this answer
 
v3
Comments
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.
--SA
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 :-).
--SA
Wendelius 11-May-12 14:05pm    
Looks right :)
Sergey Alexandrovich Kryukov 11-May-12 16:31pm    
Thank you, Mika.
--SA

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