HOME

XML Basic
XML HOME
XML Introduction
XML How to use
XML Syntax
XML Elements
XML Attributes
XML Validation
XML Browsers
XML Viewing
XML CSS Display
XML XSL Display
XML Data Islands
XML Parser
XML in Real Life

XML Advanced
XML Namespaces
XML CDATA
XML Encoding
XML Server
XML Applications
XML HTTP
XML Behaviors
XML Technologies

Examples/Quiz
XML Examples
XML Quiz


XML WebRing
Previous 5 Sites
Previous Site
Next Site
Next 5 Sites
Random Site
List Sites
Online Degrees
Please visit our sponsors !

XML Encoding

back next

XML documents can contain foreign characters like Norwegian æøå, or French êèé.

To let your XML parser understand these characters, you should save your XML documents as Unicode.


Windows 95/98 Notepad

Windows 95/98 Notepad cannot save files in Unicode format. 

You can use Notepad to edit and save XML documents that contain foreign characters (like Norwegian or French æøå and êèé),

<?xml version="1.0"?>
<note>
  <from>Jani</from>
  <to>Tove</to>
  <message>Norwegian: æøå. French: êèé</message>
</note>

But if you save the file and open it with IE 5.0, you will get an ERROR MESSAGE.


Windows 95/98 Notepad with Encoding

Windows 95/98 Notepad files must be saved with an encoding attribute. 

To avoid this error you can add an encoding attribute to your XML declaration, but you cannot use Unicode.

This encoding (open it with IE 5.0), will NOT give an error message:

<?xml version="1.0" encoding="windows-1252"?>

This encoding (open it with IE 5.0), will NOT give an error message:

<?xml version="1.0" encoding="ISO-8859-1"?>

This encoding (open it with IE 5.0), WILL give an error message:

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

This encoding (open it with IE 5.0), WILL give an error message:

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


Windows 2000 Notepad

Windows 2000 Notepad can save files as Unicode.

The Notepad editor in Windows 2000 supports Unicode. If you select to save this XML file as Unicode (note that the document does not contain any encoding attribute):

<?xml version="1.0"?>
<note>
  <from>Jani</from>
  <to>Tove</to>
  <message>Norwegian: æøå. French: êèé</message>
</note>

The following file; note_encode_none_u.xml, will NOT give an error message if you open it with IE 5.0, but if you open it with Netscape 6.2, you WILL get an error message.


Windows 2000 Notepad with Encoding

Windows 2000 Notepad files saved as Unicode use "UTF-16" encoding.

If you add an encoding attribute to XML files saved as Unicode, windows encoding values will generate an error.

This encoding (open it), will NOT give an error message:

<?xml version="1.0" encoding="windows-1252"?>

This encoding (open it), will NOT give an error message:

<?xml version="1.0" encoding="ISO-8859-1"?>

This encoding (open it), will NOT give an error message:

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

The following file; note_encode_utf16_u.xml, will NOT give an error message if you open it with IE 5.0, but if you open it with Netscape 6.2, you WILL get an error message.

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


Error Messages

If you try to load an XML document into Internet Explorer 5, you can get two different errors indicating encoding problems:

An invalid character was found in text content.

You will get this error message if a character in the XML document does not match the encoding attribute. Normally you will get this error message if your XML document contains "foreign" characters, and the file was saved with a single-byte encoding editor like Notepad, and no encoding attribute was specified. 

Switch from current encoding to specified encoding not supported.

You will get this error message if your file was saved as Unicode/UTF-16 but the encoding attribute specified a single-byte encoding like Windows-1252, ISO-8859-1 or  UTF-8. You can also get this error message if your document was saved with single-byte encoding, but the encoding attribute specified a double-byte encoding like UTF-16.


Conclusion

The conclusion is that the encoding attribute has to specify the encoding used when the document was saved. My best advice to avoid errors is:

  • Use an editor that supports encoding.
  • Make sure you know what encoding it uses.
  • Use the same encoding attribute in your XML documents.

back next

Jump to: Top of Page or HOME or Printer Friendly Printer friendly page


Search W3Schools:


What Others Say About Us

Does the world know about us? Check out these places:

Dogpile Alta Vista MSN Google Excite Lycos Yahoo Ask Jeeves


We Help You For Free. You Can Help Us!


W3Schools is for training only. We do not warrant its correctness or its fitness for use. The risk of using it remains entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.

Copyright 1999-2002 by Refsnes Data. All Rights Reserved


Validate How we converted to XHTML Validate

Domain Name Registration
Domain Name
Registration & More!



Your own Web Site?

Read W3Schools
Hosting Tutorial



$15 Domain Name
Registration
Save $20 / year!



Advertise
at W3Schools

Only 0.5 CPM



SELECTED LINKS

University Online
Master Degree
Bachelor Degree


Web Software

The Future of
Web Development


Jobs and Careers

Web Security
Web Statistics
Web Standards


PARTNERS

W3Schools
TopXML
VisualBuilder
XMLPitstop
DevelopersDex
DevGuru
Programmers Heaven
The Code Project
Tek Tips Forum
ZVON.ORG
TopXML Search