ENTITY
The ENTITY
statement is used to define entities in the DTD, for use in both the XML document associated with the DTD and the DTD itself.
Syntax
<!ENTITY [%] name [SYSTEM|PUBLIC publicID] resource [NDATA notation] >
Parameters
- name
- The name of the entity. Required for all entity definitions.
- publicID
- The public identifier for the entity. Only required if the declaration uses the PUBLIC keyword.
- resource
- The value for the entity. Required for all entity definitions. In the case of internal entities, this is a text string that is parsed and expanded. In the case of external entities, it is a Uniform Resource Identifier (URI) that identifies an external entity such as a file name or file type.
- notation
- The name of a notation declared elsewhere in the DTD using the NOTATION statement. Only required when declaring an unparsed entity through the use of the non-XML data (NDATA) keyword.
Examples
General entity (parsed internal)
The following declares an internal general entity that can be referenced as öaut;
in XML documents that use the DTD.
<!ENTITY oumlaut "&#246;">
The XML parser expands the raw entity value (&#246;) to make it part of the internal XML document. In the final parsed document output, the "&" value becomes an "&" and the value appears as "ö" in the final parsed document.
Parameter entity (parsed internal)
The following declares an internal parameter entity that can be referenced as %lists;
in other places in the DTD. This allows repeated references to the XHTML list elements, <ul>
and <ol>
.
<!ENTITY % lists "ul | ol">
Unparsed external entity
The following declares an unparsed external entity that allows you to encode links to non-XML data (in this case, an image file in GIF format) for inclusion in your XML document.
<!ENTITY image.banner SYSTEM "banner.gif" NDATA image_gif >
In this case, the use of the NDATA
keyword requires that a NOTATION
declaration for a notation called "gif" must also be used in combination with this declaration. For more information, see NOTATION.
Remarks
Entities can be used in a variety of ways. If you are not sure how to define an entity for use, the following questions might help you better understand the different conditions for using the entities you declare in the DTD:
- Is the value of the entity simply to be used as is to abbreviate a larger text string (i.e. internal entities) that might change during the life of the document? Or will it be used as a pointer to something external to the DTD or XML document (i.e. external entities), like a file name or MIME type?
- Should the URI value of the entity be parsed (i.e. expanded as part of the DTD or an XML document that uses it), or remain unparsed (i.e. the XML parser will omit its contents from the final parsed document)?
- If parsed, should the expanded entity content become part of the XML document that uses the DTD (i.e. general entities) or part of the DTD itself (i.e. parameter entities)?
See Also
ATTLIST (Attribute List) | ELEMENT | NOTATION