C# – Data is invalid error when loading XML

c++domxml

I am trying to load a very basic XML document but everytime I get to the LoadXml(string url) line, the program crashes and reports an exception ("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 in IE fine):

<note>
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
</note>

This is pasted exactly as is with no whitespace.

I can't see anything wrong with this code, the stack trace doesn't tell me much and I suspect there is an environmental issue somewhere. Does anyone have any ideas?

EDIT: The formatting of the XML isn't right. The XML is the same as the sample document on here: http://w3schools.com/xml/default.asp

Best Solution

Use Load() instead of LoadXml().