XML technologies / XML / Perl & XML / Introduction to XML / Unicode, Character sets and encodings

(Excerpt from "Perl & XML" by Erik T. Ray & Jason McIntosh)

At a low level, computers treat text as a finite sequence of positive integers mapped through encoding tables to characters, including controls such as line endings and tabs. The most important character set is US-ASCII, containing 128 characters: Latin uppercase and lowercase letters, digits, symbols, spaces, and printing controls inherited from daisy-wheel printers. Adding an eighth bit doubles the seven-bit character set, producing sets such as ISO Latin-1, used on many Unix systems. It adds Central European characters, German umlauts, accents, ligatures, markers for Footnotes and legal symbols. Unfortunately, creative and proud humanity has devised far more characters and symbols than a mere eight-bit character set can accommodate.

This led to Unicode, increasingly the standard for representing every kind of document and source text ever written. Depending on its variant, it uses up to 32 bits per character, allowing many millions of characters. For over a decade, the Unicode Consortium has been filling this space with Chinese Han characters, mathematical symbols, German playing-card symbols, and more. Enough room remains for this millennium, perhaps even the next.

After this praise of Unicode, it is hardly surprising that XML’s default character encoding is the Unicode variant UTF-8. UTF-8 is variable-length: US-ASCII characters occupy one byte, other characters, especially ISO Latin-1, two bytes, and others up to six. A whole XML document can use single-byte characters if you stick to ISO Latin-1, ranging from 1 to 255, and occasionally use entity references. Special characters, including large amounts of Asian text, are easy to encode in UTF-8. Unicode-aware processors display the correct characters; older applications may simply pass multibyte characters through unchanged. Perl has supported UTF-8 since version 5.6, with improving support. We return to Unicode in Perl in XML basics: reading and writing.

  

  

 

 

 

back to top