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):
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.
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.