{"id":63,"date":"2005-08-27T14:57:32","date_gmt":"2005-08-27T14:57:32","guid":{"rendered":"http:\/\/bdragon.com\/?p=63"},"modified":"2021-05-18T10:02:52","modified_gmt":"2021-05-18T16:02:52","slug":"xmlexception-the-data-at-the-root-level-is-invalid","status":"publish","type":"post","link":"https:\/\/bdragon.com\/lair\/2005\/08\/xmlexception-the-data-at-the-root-level-is-invalid\/","title":{"rendered":"XmlException: The data at the root level is invalid&#8230;."},"content":{"rendered":"<div class=\"entry\">\n\n\n<p><code>XmlException: The data at the root level is invalid. Line 1, position 1.<\/code><\/p>\n\n\n\n<p>This might be a really obscure (or dumb?) ASP.NET \/ C# problem, but again I thought I&#8217;d post something about it in case it helps someone else searching about this issue&#8230;.<\/p>\n\n\n\n<p>I was getting an exception when loading an XML file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Error with ... xml\\nav.xml: System.Xml.XmlException:\r\nThe data at the root level is invalid. Line 1, position 1.\r\nat System.Xml.XmlTextReader.ParseRoot()\r\nat System.Xml.XmlTextReader.Read()\r\nat System.Xml.XmlValidatingReader.ReadWithCollectTextToken()\r\nat System.Xml.XmlValidatingReader.Read()\r\nat System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)\r\nat System.Xml.XmlDocument.Load(XmlReader reader)\r\nat System.Xml.XmlDocument.LoadXml(String xml)<\/code><\/pre>\n\n\n\n<!--more-->\n\n\n\n<p>Using the following code:<\/p>\n\n\n\n<p><code>docXml.LoadXml(xml);<\/code><\/p>\n\n\n\n<p>Searching for others&#8217; advice \/ solutions for such a problem on the web didn&#8217;t help very much&#8230; it kept happening no matter what I was trying.<\/p>\n\n\n\n<p>Turned out the problem was very very simple to fix (as they sometimes are) &#8211; it was just a typo. The variable &#8220;xml&#8221; was a full file path to an xml FILE I was trying to load, and silly me, you have to use docXml.Load() to load an xml FILE, not docXml.LoadXml() &#8211; the typo must have gotten in there from a poor use of VS.NET Intellisense or something (auto-completing LoadXml instead of just Load) &#8211; doh!<\/p>\n\n\n\n<p>Changing the code to:<\/p>\n\n\n\n<p><code>docXml.Load(xml);<\/code><\/p>\n\n\n\n<p>Worked just fine (of course).<\/p>\n\n\n\n<p>Like I mentioned, just in case this helps someone else!<\/p>\n\n\n<\/div>","protected":false},"excerpt":{"rendered":"<p>XmlException: The data at the root level is invalid. Line 1, position 1. This might be a really obscure (or dumb?) ASP.NET \/ C# problem, but again I thought I&#8217;d post something about it in case it helps someone else searching about this issue&#8230;. I was getting an exception when loading an XML file:<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[43],"tags":[57,53,54,55,56,58],"class_list":{"0":"post-63","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-web-stuff","7":"tag-net","8":"tag-asp-net","9":"tag-c-sharp","10":"tag-csharp","11":"tag-dotnet","12":"tag-microsoft","13":"anons"},"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/peSL2o-11","jetpack_sharing_enabled":true,"jetpack_likes_enabled":false,"_links":{"self":[{"href":"https:\/\/bdragon.com\/lair\/wp-json\/wp\/v2\/posts\/63","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bdragon.com\/lair\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bdragon.com\/lair\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bdragon.com\/lair\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/bdragon.com\/lair\/wp-json\/wp\/v2\/comments?post=63"}],"version-history":[{"count":0,"href":"https:\/\/bdragon.com\/lair\/wp-json\/wp\/v2\/posts\/63\/revisions"}],"wp:attachment":[{"href":"https:\/\/bdragon.com\/lair\/wp-json\/wp\/v2\/media?parent=63"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bdragon.com\/lair\/wp-json\/wp\/v2\/categories?post=63"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bdragon.com\/lair\/wp-json\/wp\/v2\/tags?post=63"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}