Section 15.6.  Character references

Prev don't be afraid of buying books Next

15.6. Character references

It is not usually convenient to type in characters that are not available on the keyboard. With many text editors, it is not even possible to do so. XML allows you to insert such a character with a character reference.

If, for instance, you wanted to insert a character from the "International Phonetic Alphabet", you could spend a long time looking for a combination of keyboard, operating system and text editor that would make that straightforward. XML simply allows you to refer to the character by its Unicode number.

15.6.1 Reference by decimal number

Here is an example:

Example 15-17. Decimal character reference
 <P>Here is a reference to Unicode character 161: &#161;.</P> 

Unicode is a character set. The character numbered 161 in Unicode happens to be the inverted exclamation mark.

15.6.2 Reference by hexadecimal number

Alternatively, you could use the hexadecimal (hex) value of the character number to reference it:

Example 15-18. Hex character reference
 <P>Here is a different reference to Unicode character 161: &#xA1;. 

Hex is a numbering system often used by computer programmers that translates naturally into the binary codes that computers use. The Unicode Standard book uses hex, so those that have that book will probably prefer this type of character reference over the other (whether they are programmers or not).

Note that character references are not entity references, though they look similar to them. Entities have names and values, but character references only have character numbers. In an XML document, all entities except the predefined ones must be declared. But a character reference does not require a declaration; it is just a really verbose way to type a character (but often the only way).

15.6.3 Reference by name (via an entity)

Because Unicode numbers are hard to remember, it is often useful to declare entities that stand in for them:

Example 15-19. Entity declaration for a Unicode character
 <!ENTITY inverted-exclamation "&#161;"> 

Amazon


XML in Office 2003. Information Sharing with Desktop XML
XML in Office 2003: Information Sharing with Desktop XML
ISBN: 013142193X
EAN: 2147483647
Year: 2003
Pages: 176

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net