Incomplete Leo

Something from my heart

XmlException: The data at the root level is invalid….

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’d post something about it in case it helps someone else searching about this issue….

I was getting an exception when loading an XML file:

Error with … xmlnav.xml: System.Xml.XmlException:   The data at the root level is invalid. Line 1, position 1.

Using the following code:

docXml.LoadXml(xml);

Searching for others’ advice / solutions for such a problem on the web didn’t help very much… it kept happening no matter what I was trying.

Turned out the problem was very very simple to fix (as they sometimes are) – it was just a typo. The variable “xml” 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() – the typo must have gotten in there from a poor use of VS.NET Intellisense or something (auto-completing LoadXml instead of just Load) – doh!

Changing the code to:

docXml.Load(xml);

Worked just fine (of course).

Like I mentioned, just in case this helps someone else!

Tháng Một 9, 2007 - Posted by | .NET Related

2 phản hồi »

  1. Thanks,

    It really helped.

    Phản hồi bởi Dhaval | Tháng Sáu 30, 2008 | Trả lời

  2. Thanks, it helped me as well🙂

    Phản hồi bởi Nihit | Tháng Hai 5, 2009 | Trả lời


Gửi phản hồi

Mời bạn điền thông tin vào ô dưới đây hoặc kích vào một biểu tượng để đăng nhập:

WordPress.com Logo

Bạn đang bình luận bằng tài khoản WordPress.com Log Out / Thay đổi )

Twitter picture

Bạn đang bình luận bằng tài khoản Twitter Log Out / Thay đổi )

Facebook photo

Bạn đang bình luận bằng tài khoản Facebook Log Out / Thay đổi )

Google+ photo

Bạn đang bình luận bằng tài khoản Google+ Log Out / Thay đổi )

Connecting to %s

%d bloggers like this: