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-exapnsion1-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)

general-entities/entity-expansion0

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

Result

<!doctype test [
	<!element test - - (sub+)>
	<!element sub - - (#pcdata)>
	<!entity ent1 "basic parsed entity replacement text">
]>
<test><sub>basic parsed entity replacement text</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>

Result

<!doctype test [
	<!element test - - (sub+)>
	<!element sub - - (#pcdata)>
	<!entity ent1 system "entity-expansion1-external-entity.sgm">
]>
<test><sub>Basic expansion text from external parsed entity
</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>

Result

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

Result

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

Result

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

Result

<!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="text-to-be-fetched-into-attr 
"></sub></test>