300x250 AD TOP

Wednesday, June 29, 2011

Tagged under: ,

Problem in Loading xml with encoding UTF 16 using XDocument

Problem in Loading xml with encoding UTF 16 using XDocument


I was getting error " There is no Unicode byte order mark. Cannot switch to Unicode, when  i was  trying to read the xml document using XDocument method .
Xml had encoding


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

When i removed encoding manually.It works perfectly.
I had tried
XDocument xdoc = XDocument.Load(path);

So what was the problem ?

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

Or

using (StreamReader sr = new StreamReader(path, true))
{
XDocument xdoc = XDocument.Load(sr);
}


That solved my problem.

0 comments:

Post a Comment