Data at the root level is invalid. Line 1, position 1 -why do I get this error while loading an xml file?

sari k picture sari k · Sep 25, 2011 · Viewed 53.6k times · Source

Data at the root level is invalid. Line 1, position 1 -why I get this error while load xml file

this my code:

XmlDocument xmlDoc=new XmlDocument();
xmlDoc.LoadXml("file.xml");

Answer

John Saunders picture John Saunders · Sep 25, 2011

The LoadXml method is for loading an XML string directly. You want to use the Load method instead.