Invalid error while loading XML
I am trying to load a very simple XML document, but every time I hit the LoadXml line (url line) the program crashes and reports an exception ("The data at the root level is invalid. Line 1, position 1" XmlException).
XmlDocument xmldoc = new XmlDocument();
xmldoc.LoadXml(@"C:\Websites\TestHarness\TestHarness\TestHarness\ExampleXml.xml");
XmlNode node = xmldoc.DocumentElement;
My XML looks like this (this is a sample XML document from W3Schools and it opens fine in IE):
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
This is inserted exactly the same as without spaces.
I don't see anything wrong with this code, the stack trace doesn't tell me much and I suspect there is some kind of environmental issue. Does anyone have any ideas?
EDIT: XML formatting is wrong. XML is the same as sample document here: http://w3schools.com/xml/default.asp
source to share
Yes, you are loading the filename as xml. But you also lack the xml encoding .... The Xml format does not allow the use of such text. This xml should be written live:
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Here is a nice tool for coding the web.
Hope this helps ... :)
source to share