10.3 Entity and Character References

Team-Fly    

 
Webmaster in a Nutshell, 3rd Edition
By Robert Eckstein, Stephen Spainhour
Table of Contents
Chapter 10.  XML


Entity references are used as substitutions for specific characters (or any string substitution) in XML. A common use for entity references is to denote document symbols that might otherwise be mistaken for markup by an XML processor. XML predefines five entity references for you, which are substitutions for basic markup symbols. However, you can define as many entity references as you like in your own DTD. (See the next section.)

Entity references always begin with an ampersand (&) and end with a semicolon (;). They cannot appear inside a CDATA section but can be used anywhere else. Predefined entities in XML are shown in the following table:

Entity

Char

Notes

&

&

Do not use inside processing instructions.

<

<

Use inside attribute values quoted with ".

&gt;

>

Use after ]] in normal text and inside processing instructions.

&quot;

"

Use inside attribute values quoted with ".

&apos;

'

Use inside attribute values quoted with '.

In addition, you can provide character references for Unicode characters with a numeric character reference. A decimal character reference consists of the string &#, followed by the decimal number representing the character, and finally, a semicolon (;). For hexadecimal character references, the string &#x is followed first by the hexadecimal number representing the character and then a semicolon. For example, to represent the copyright character, you could use either of the following lines:

 This document is &#169; 2001 by OReilly and Assoc. This document is &#xA9; 2001 by OReilly and Assoc. 

The character reference is replaced with the "circled-C" () copyright character when the document is formatted.


Team-Fly    
Top


Webmaster in a Nutshell
Webmaster in a Nutshell, Third Edition
ISBN: 0596003579
EAN: 2147483647
Year: 2002
Pages: 412

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