Character and entity references provide ways to include information in XML documents by reference rather than by typing characters into the document directly. This can be useful in cases in which:
For content representation, XML provides a number of syntactical constructs that start with an ampersand (&) and end with a semi-colon (;).
Character references provide a way to insert Unicode characters that are identified by a number pointing to a Unicode code point. Code points can be identified using either decimal or hexadecimal notation.
For example, to insert the Euro symbol, a character still missing from many keyboards, you can insert €
or €
into a document.
The following table lists the five built-in entities for the characters used for XML markup.
Entity | Entity Reference | Meaning |
---|---|---|
lt | < | < (less than) |
gt | > | > (greater than) |
amp | & | & (ampersand) |
apos | ' | ' (apostrophe or single quote) |
quot | " | " (double quote) |
In cases where the character might cause the XML parser to misinterpret the document structure, use the entity instead of typing the character. The '
and "
entity references are most commonly used in attribute values.
To write Me&You, for example, use Me&You
. For a<b, use a<b
. For b>c, use b>c
.
You can also define your own entities, much like HTML defines a set of entities for use in HTML. &ap
os is not recognized as an HTML file; $#....
must be used when transforming to HTML.
If you're working with a document type definition (DTD) that has defined entities, you can reference them in document content by using the following syntax.
&entityName;