Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / July 2008

Tip: Looking for answers? Try searching our database.

Cannot Switch to Unicode Error

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Co Co Net - 21 Jul 2008 21:59 GMT
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 - 22 Jul 2008 08:09 GMT
> I made an XML document "by hand" and wrote it to a file.
>
[quoted text clipped - 9 lines]
>
> 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.

Signature

Joe Fawcett (MVP - XML)

http://joe.fawcett.name

Martin Honnen - 22 Jul 2008 12:25 GMT
> I made an XML document "by hand" and wrote it to a file.
>
[quoted text clipped - 9 lines]
>
> 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.

Signature

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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.