Best visual-studio-2008 questions in December 2010

Loading xml with encoding UTF 16 using XDocument

5 votes

Hi,

I am trying to read the xml document using XDocument method . but i am getting an error when xml has

<?xml version="1.0" encoding="utf-16"?>

When i removed encoding manually.It works perfectly.

I am getting error " There is no Unicode byte order mark. Cannot switch to Unicode. "

i tried searching and i landed up here-->

Why does C# XmlDocument.LoadXml(string) fail when an XML header is included?

But could not solve my problem.

My code :

XDocument xdoc = XDocument.Load(path);

Any suggestions ??

thank you.

Hi !!

Thank you Tuzo, for the answer !!

Guys,

I tried , and found another way of doing it !!

XDocument xdoc = XDocument.Parse(System.IO.File.ReadAllLines(path));

This think solved the problem.

Thank you everyone.