Easy Tutorial
❮ Xml Intro Xml View ❯

XML Encoding


XML documents can contain non-ASCII characters, such as Norwegian æ ø å, or French ê è é.

To avoid errors, it is necessary to specify the XML encoding, or save the XML file as Unicode.


XML Encoding Errors

When you load an XML document, you may encounter two different errors indicating encoding issues:

Invalid character found in text content.

If your XML contains non-ASCII characters and the file is saved as single-byte ANSI (or ASCII) without specifying an encoding, you will get an error.

XML file with single-byte encoding attribute.

Same single-byte XML file without encoding attribute.

Switching to an unsupported specified encoding

If your XML file is saved as double-byte Unicode (or UTF-16) with a specified single-byte encoding (WINDOWS-1252, ISO-8859-1, UTF-8), you will get an error.

If your XML file is saved as single-byte ANSI (or ASCII) with a specified double-byte encoding (UTF-16), you will also get an error.

Double-byte XML file without encoding.

Same double-byte XML file with single-byte encoding.


Windows Notepad

Windows Notepad defaults to saving files as single-byte ANSI (ASCII).

If you choose "Save As...", you can specify ANSI, UTF-8, Unicode (UTF-16), or Unicode Big.

Save the following XML as ANSI, UTF-8, and Unicode (note that the document does not contain any encoding attribute).

Try dragging the file into your browser and observe the results. Different browsers will display different results.

Experiences with different encodings:

Please try:

Save with correct encoding

Save with wrong encoding


Conclusion

❮ Xml Intro Xml View ❯