Please visit our sponsors !
XML Encoding
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.
Jump to: Top of Page
or HOME or
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
|