Connecting Tech Pros Worldwide Help | Site Map

Cannot Switch to Unicode Error

  #1  
Old July 21st, 2008, 10:05 PM
Co Co Net
Guest
 
Posts: n/a

I made an XML document "by hand" and wrote it to a file.

I then tried to read it with an XmlTextReader wrapping a FileStream. I
got an XmlException about "cannot switch to Unicode" or something.
Changing the from this:

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

to this

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

lets it run - why?


  #2  
Old July 22nd, 2008, 08:15 AM
Joe Fawcett
Guest
 
Posts: n/a

re: Cannot Switch to Unicode Error


"Co Co Net" <coconet@community.nospamwrote in message
news:lct984lu6m6qbplp62jqdgvqmtp11qkeqp@4ax.com...
Quote:
>
I made an XML document "by hand" and wrote it to a file.
>
I then tried to read it with an XmlTextReader wrapping a FileStream. I
got an XmlException about "cannot switch to Unicode" or something.
Changing the from this:
>
<?xml version="1.0" encoding="utf-16"?>
>
to this
>
<?xml version="1.0" encoding="utf-8"?>
>
lets it run - why?
>
>
Most likely because your actual encoding clashes with the one stated in the
version declaration..
If you want to fix it then give a minimal example of how you created your
file and how you attempt to read it.

--

Joe Fawcett (MVP - XML)

http://joe.fawcett.name


  #3  
Old July 22nd, 2008, 12:35 PM
Martin Honnen
Guest
 
Posts: n/a

re: Cannot Switch to Unicode Error


Co Co Net wrote:
Quote:
I made an XML document "by hand" and wrote it to a file.
>
I then tried to read it with an XmlTextReader wrapping a FileStream. I
got an XmlException about "cannot switch to Unicode" or something.
Changing the from this:
>
<?xml version="1.0" encoding="utf-16"?>
>
to this
>
<?xml version="1.0" encoding="utf-8"?>
>
lets it run - why?
That sounds to me as if the XML document created "by hand" has a BOM
indicating UTF-8 while you inserted an XML declaration declaring the
encoding as UTF-16. So check how you saved the XML document, your editor
might allow you to choose the encoding, if you want UTF-16 then make
sure you save with that encoding.


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
parsing problem with unicode (utf-16) xml file srikantht answers 9 March 13th, 2006 01:55 PM
Access expoert reports to PDF using PDF writer 6.0 issues Grasshopper answers 11 November 13th, 2005 07:08 AM
incorrect encoding after serialisation to XML Stephen answers 4 November 12th, 2005 03:45 AM
Error: There is no Unicode byte order mark. Cannot switch to Unicode Jim P. answers 1 November 12th, 2005 02:32 AM