Connecting Tech Pros Worldwide Help | Site Map

Cannot Switch to Unicode Error

Co Co Net
Guest
 
Posts: n/a
#1: Jul 21 '08

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?


Joe Fawcett
Guest
 
Posts: n/a
#2: Jul 22 '08

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


Martin Honnen
Guest
 
Posts: n/a
#3: Jul 22 '08

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