SGML

General Entity Examples

general-entities/entity-expansion0
Basic internal general entity expansion
general-entities/entity-expansion1

Basic external general entity expansion (where the file entity-expansion1-external-entity.sgm contains the text Basic expansion text from external parsed entity)

general-entities/entity-expansion-on-attr0 general-entities/entity-expansion-on-attr1 general-entities/entity-expansion-on-attr2
Examples for an entity reference used in an attribute value (note that within replacement text put in a double-quoted value literal in a declaration, a verbatim single-quote character can be used unquoted; likewise, within a single-quoted value literal, a verbatim double-quote character can be used unquoted; otherwise, single- or double-quote characters as verbatim text are specified as character entity reference within quoted literals); expansion into attribute value encodes single and double quote character in the replacement text into character entity references
general-entities/entity-expansion-on-attr3

Example for an external entity reference used in an attribute value (where the file entity-expansion-on-attr3-external-entity.ent contains the text text-to-be-fetched-into-attr)

Note: To process SGML from the example sources, copy and paste an example source, store it into a file with the ".sgm" file extension, and invoke
sgmlproc <your-file.sgm>
where <your-file.sgm> is replaced by the actual file used for storing.

general-entities/entity-expansion0

<!doctype test [
	<!element test - - (sub+)>
	<!element sub - - (#pcdata)>
	<!entity ent1 "basic parsed entity replacement text">
]>
<test><sub>&ent1;</sub></test>

general-entities/entity-expansion1

<!doctype test [
	<!element test - - (sub+)>
	<!element sub - - (#pcdata)>
	<!entity ent1 system "entity-expansion1-external-entity.sgm">
]>
<test><sub>&ent1;</sub></test>

general-entities/entity-expansion-on-attr0

<!doctype test [
	<!element test - - (#pcdata)>
	<!attlist test att cdata #implied>
	<!entity entwithquote "single quote following: '">
]>
<test att='&entwithquote'></test>

general-entities/entity-expansion-on-attr1

<!doctype test [
	<!element test - - (#pcdata)>
	<!attlist test att cdata #implied>
	<!entity entwithquote 'double quote following: "'>
]>
<test att="&entwithquote"></test>

general-entities/entity-expansion-on-attr2

<!doctype test [
	<!element test - - (#pcdata)>
	<!attlist test att cdata #implied>
	<!entity entwithquote 'double quote following: "'>
	<!entity referencedent 'contains ref to &entwithquote;'>
]>
<test att="&referencedent;"></test>

general-entities/entity-expansion-on-attr3

<!doctype test [
	<!element test - - (sub+)>
	<!element sub - - (#pcdata)>
	<!attlist sub att cdata #implied>
	<!entity ent system "entity-expansion-on-attr3-external-entity.ent">
]>
<test><sub att="&ent"></sub></test>