4.5 Entity Reference Declarations


Entities are variables that define shortcut names. The parsing process replaces them with common text. You can declare entities either internally or externally.

"General entities" are entities for use within the document content (see Section 4.5.1). The XML Recommendation refers to these entities using the unqualified term "entity." By comparison, "parameter entities" are parsed entities for use only within the DTD (see Section 4.5.2). General and parameter entities occupy different namespaces; a parameter entity and a general entity with the same name are two distinct entities.

Table 4-5. Attribute Default Values
Value Explanation
#DEFAULT value The attribute's default value.
#REQUIRED Document authors must include the attribute value in the element. Use a required attribute when you do not have an option for a default value but still want to force the attribute to be present.
#IMPLIED Use of the #IMPLIED attribute is optional. Use an implied attribute when you do not have an option for a default value and you do not want to force the author to include an attribute.
#FIXED value The attribute value is fixed. A fixed value does not allow document authors to change the attribute value. If a document author includes another value, the XML parser returns an error.

4.5.1 Internal General Entity Reference Declarations

You define internal general entity references in the DTD by using an "<!ENTITY>" declaration. General entity values cannot contain a percent sign ("%"), ampersand ("&"), or double quote (" " "), unless these characters are inserted through character references. The syntax for an entity declara tion has the following format, where "name" is the abbreviation for the replacement text:

 <!ENTITY name "replacement text"> 

Make sure to enclose the replacement text in quotes, as it might contain white spaces.

You can use general entity references in the DTD only where their use will be part of document content. In other places in the DTD, you must use parameter entities as described in Section 4.5.2.

4.5.2 Parameter Entity Reference Declarations

Parameter entity references are similar to general entity references except that they begin with a percent sign ("%") and can appear only in the DTD. Developers frequently use parameter entities to encapsulate part of a declaration that is used frequently and has multiple variants. Parameter entity references also prove useful when multiple elements use the same content model for example, when you want to share common lists of children and elements between elements. You must declare parameter entity references before using them.

A parameter entity reference declaration has the following syntax:

 <!ENTITY % name "replacement text"> 

By using parameter entities, you can shorten the declarations of other elements and attributes. For example, you can place parameter entity references in an internal DTD subset when they provide whole declarations. You can place parameter entities inside a declaration in an external DTD subset to define content models, element names, and other parts of declarations in the DTD subset.



Secure XML(c) The New Syntax for Signatures and Encryption
Secure XML: The New Syntax for Signatures and Encryption
ISBN: 0201756056
EAN: 2147483647
Year: 2005
Pages: 186

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