Everipedia Logo
Everipedia is now IQ.wiki - Join the IQ Brainlist and our Discord for early access to editing on the new platform and to participate in the beta testing.
Numeric character reference

Numeric character reference

A numeric character reference (NCR) is a common markup construct used in SGML and SGML-derived markup languages such as HTML and XML. It consists of a short sequence of characters that, in turn, represents a single character. Since WebSgml, XML and HTML 4, the code points of the Universal Character Set (UCS) of Unicode are used. NCRs are typically used in order to represent characters that are not directly encodable in a particular document (for example, because they are international characters that don't fit in the 8-bit character set being used, or because they have special syntactic meaning in the language). When the document is interpreted by a markup-aware reader, each NCR is treated as if it were the character it represents.

Examples

In SGML, HTML, and XML, the following are all valid numeric character references for the Greek capital letter Sigma

Numerical character reference of U+03A3 Σ GREEK CAPITAL LETTER SIGMA(3A316 = 931)
Unicode characterNumerical baseNumerical reference in markupEffect
U+03A3DecimalΣΣ
U+03A3DecimalΣΣ
U+03A3HexadecimalΣΣ
U+03A3HexadecimalΣΣ
U+03A3HexadecimalΣΣ

In SGML, HTML, and XML, the following are all valid numeric character references for the Latin capital letter AE

Numerical character reference of U+00C6 Æ LATIN CAPITAL LETTER AE
Unicode characterNumerical baseNumerical reference in markupEffect
U+00C6DecimalÆÆ
U+00C6HexadecimalÆÆ

In SGML, HTML, and XML, the following are all valid numeric character references for the Latin small letter sharp s ß

Numerical character reference of U+00DF ß LATIN SMALL LETTER SHARP S
Unicode characterNumerical baseNumerical reference in markupEffect
U+00DFDecimalßß
U+00DFHexadecimalßß

List of numeric character references for the printable ASCII characters:

Unicode characterCharacter
Reference
(decimal)
Character
Reference
(hexadecimal)
Effect
U+0020 (space)
U+0021!!!
U+0022"""
U+0023##

U+0024$$$
U+0025%%%
U+0026&&&
U+0027'''
U+0028(((
U+0029)))
U+002A**
U+002B++
U+002C,,,
U+002D--
U+002E...
U+002F///
U+0030000
U+0031111
U+0032222
U+0033333
U+0034444
U+0035555
U+0036666
U+0037777
U+0038888
U+0039999
U+003A:::
U+003B;;;
U+003C<<<
U+003D===
U+003E>>
U+003F???
U+0040@@@
U+0041AAA
U+0042BBB
U+0043CCC
U+0044DDD
U+0045EEE
U+0046FFF
U+0047GGG
U+0048HHH
U+0049III
U+004AJJJ
U+004BKKK
U+004CLLL
U+004DMMM
U+004ENNN
U+004FOOO
U+0050PPP
U+0051QQQ
U+0052RRR
U+0053SSS
U+0054TTT
U+0055UUU
U+0056VVV
U+0057WWW
U+0058XXX
U+0059YYY
U+005AZZZ
U+005B[[[
U+005C\\\
U+005D]]]
U+005E^^^
U+005F___
U+0060``'
U+0061aaa
U+0062bbb
U+0063ccc
U+0064ddd
U+0065eee
U+0066fff
U+0067ggg
U+0068hhh
U+0069iii
U+006Ajjj
U+006Bkkk
U+006Clll
U+006Dmmm
U+006Ennn
U+006Fooo
U+0070ppp
U+0071qqq
U+0072rrr
U+0073sss
U+0074ttt
U+0075uuu
U+0076vvv
U+0077www
U+0078xxx
U+0079yyy
U+007Azzz
U+007B{{{
U+007C||
U+007D}}}
U+007E~~~

Discussion

Markup languages are typically defined in terms of UCS or Unicode characters. That is, a document consists, at its most fundamental level of abstraction, of a sequence of characters, which are abstract units that exist independently of any encoding.

Ideally, when the characters of a document utilizing a markup language are encoded for storage or transmission over a network as a sequence of bits, the encoding that is used will be one that supports representing each and every character in the document, if not in the whole of Unicode, directly as a particular bit sequence.

Sometimes, though, for reasons of convenience or due to technical limitations, documents are encoded with an encoding that cannot represent some characters directly. For example, the widely used encodings based on ISO 8859 can only represent, at most, 256 unique characters as one 8-bit byte each.

Documents are rarely, in practice, ever allowed to use more than one encoding internally, so the onus is usually on the markup language to provide a means for document authors to express unencodable characters in terms of encodable ones. This is generally done through some kind of "escaping" mechanism.

The SGML-based markup languages allow document authors to use special sequences of characters from the ASCII range (the first 128 code points of Unicode) to represent, or reference, any Unicode character, regardless of whether the character being represented is directly available in the document's encoding. These special sequences are character references.

Character references that are based on the referenced character's UCS or Unicode code point are called numeric character references. In HTML 4 and in all versions of XHTML and XML, the code point can be expressed either as a decimal (base 10) number or as a hexadecimal (base 16) number. The syntax is as follows:

Character U+0026 (ampersand), followed by character U+0023 (number sign), followed by one of the following choices:

  • one or more decimal digits zero (U+0030) through nine (U+0039); or

  • character U+0078 ("x") followed by one or more hexadecimal digits, which are zero (U+0030) through nine (U+0039), Latin capital letter A (U+0041) through F (U+0046), and Latin small letter a (U+0061) through f (U+0066);

all followed by character U+003B (semicolon). Older versions of HTML disallowed the hexadecimal syntax.

The characters that comprise a numeric character reference can be represented in every character encoding used in computing and telecommunications today, so there is no risk of the reference itself being unencodable.

There is another kind of character reference called a character entity reference, which allows a character to be referred to by a name instead of a number. (Naming a character creates a character entity.) HTML defines some character entities, but not many; all other characters can only be included by direct encoding or using NCRs.

Restrictions

The Universal Character Set defined by ISO 10646 is the "document character set" of SGML, HTML 4, so by default, any character in such a document, and any character referenced in such a document, must be in the UCS.

While the syntax of SGML does not prohibit references to invalid or unassigned code points, such as �, SGML-derived markup languages such as HTML and XML can, and often do, restrict numeric character references to only those code points that are assigned to characters.

Restrictions may also apply for other reasons. For example, in HTML 4, , which is a reference to a non-printing "form feed" control character, is allowed because a form feed character is allowed. But in XML, the form feed character cannot be used, not even by reference. As another example, �, which is a reference to another control character, is not allowed to be used or referenced in either HTML or XML, but when used in HTML, it is usually not flagged as an error by web browsers – some of which interpret it as a reference to the character represented by code value 128 in the Windows-1252 encoding for compatibility reasons. This character, "€", has to be represented as € in a standard-compliant HTML code. As a further example, prior to the publication of XML 1.0 Second Edition on October 6, 2000, XML 1.0 was based on an older version of ISO 10646 and prohibited using characters above U+FFFD, except in character data, thus making a reference like (U+10000) illegal. In XML 1.1 and newer editions of XML 1.0, such a reference is allowed, because the available character repertoire was explicitly extended.

Markup languages also place restrictions on where character references can occur.

Compatibility issues

In the initial versions of SGML and HTML, numeric character references were interpreted in relationship to the document character encoding, rather than Unicode. For Latin-script documents, numeric character references to characters between x80 and x9F in those documents will not be correct against Unicode, and must be recoded. HTML standards prior to HTML 4 only supported Western Latin script documents: the treatment of character references above #7F may vary between applications and national conventions.

For example, as mentioned above, the correct numeric character reference for the Euro sign "€" U+20AC when using Unicode is decimal € and hexadecimal €. However, if using tools supporting obsolete implementations of HTML, the reference � (Euro in Cp1252 code page) or ¤ (Euro in ISO/IEC 8859-15 ) may work.

As another example, if some text was created originally MacRoman character set, the left double quotation mark " will be represented with code point xD2. This will not display properly in a system expecting a document encoded as UTF-8, ISO 8859-1, or CP1252, where this code point is occupied by the letter Ò. The correct numeric character reference for " in HTML 4 and newer is “, because U+201C is its UCS code. In some systems, the named character reference “ may also be available.

See also

  • List of XML and HTML character entity references

References

[1]
Citation Linken.wikipedia.orgThe original version of this page is from Wikipedia, you can edit the page right here on Everipedia.Text is available under the Creative Commons Attribution-ShareAlike License.Additional terms may apply.See everipedia.org/everipedia-termsfor further details.Images/media credited individually (click the icon for details).
Sep 19, 2019, 5:15 PM