SGML

Attribute Declaration and Use Examples

attributes/attr-name0

Example for attributes with declared value NAME

attributes/attr-names0

Example for attributes with declared value NAMES

attributes/attr-entity0
Example for attributes with declared value `ENTITY
attributes/attr-entities0

Example for attributes with declared value ENTITIES

attributes/attr-id0 attributes/attr-ids0

Examples for attributes with declared value ID and IDREF/IDREFS

attributes/attr-number0

Example for attributes with declared value NUMBER

attributes/attr-numbers0

Example for attributes with declared value NUMBERS

attributes/attr-nutoken0

Example for attributes with declared value NUTOKEN

attributes/attlist10
Example for declaring multiple attributes in a single declaration
attributes/attlist11 attributes/attlist12 attributes/attlist13

Examples for declaring and using #FIXED attributes; either the value a1val must be specified for the a1 attribute, or the attribute must be omitted (in which case it gets defaulted to a1val), but specifying any other value than a1val for the a1 attribute is invalid

attributes/attlist3 attributes/attlist4 attributes/attlist5 attributes/attlist7

Basic example for enumerated values (using #REQUIRED semantics);

attribute names (and the = value indicator character) can be omitted for specifying attributes declared with enumerated values, but only if the enumerated value is unique among all enumerated values for all attributes of the containing DTD;

Note that prior to the WebSGML revision of SGML (ISO 8879 Annex K) SGML required this restriction, ie. all enumerated values of all attribute declarations in a DTD (not just those applying to a given element) must be distinct

attributes/attlist15 attributes/attlist16 attributes/attlist16d

Examples for declaring and using enumerated values for attributes; when declaring a default value (attlist16), that default value will be implied when not specified in content; but if it is specified in content, the attribute will have the specified rather than the default value (provided the specified value is among the permitted enumerated values); moreover, when declaring a default or #FIXED value, the declared default value must be among the permitted enumerated values;

as attlist16 and attlist16d show, any attribute value (CDATA, enumerated values, NAME or NMTOKEN declared value) can, but doen't need to be quoted (in single or double quotes) in declarations or in content; moreover, enumerated values are subject to the SYNTAX NAMECASE GENERAL settings in the SGML declaration

attributes/attlist17
Example for declaring an attribute list for a group of elements, rather than just a single element
attributes/attlist18

Example for declaring the empty string as default value for a CDATA attribute

attributes/notation-attr0

Example for attributes with declared value NOTATION

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.

attributes/attr-name0

<!DOCTYPE test [
	<!ELEMENT test - - (#PCDATA)>
	<!ATTLIST test n NAME #REQUIRED>
]>
<test n=aname></test>

attributes/attr-names0

<!DOCTYPE test [
	<!ELEMENT test - - (#PCDATA)>
	<!ATTLIST test nn NAMES #REQUIRED>
]>
<test nn="aname another"></test>

attributes/attr-entity0

<!DOCTYPE test [
	<!ENTITY ent "bla">
	<!ELEMENT test - - (#PCDATA)>
	<!ATTLIST test testatt ENTITY #REQUIRED>
]>
<test testatt=ent></test>

attributes/attr-entities0

<!DOCTYPE test [
	<!ENTITY ent "bla">
	<!ENTITY another "fasel">
	<!ELEMENT test - - (#PCDATA)>
	<!ATTLIST test testatt ENTITIES #REQUIRED>
]>
<test testatt="ent another"></test>

attributes/attr-id0

<!DOCTYPE test [
	<!ELEMENT test - - (sub+)>
	<!ELEMENT sub - - (#PCDATA)>
	<!ATTLIST test i ID #IMPLIED>
	<!ATTLIST sub i ID #IMPLIED ir IDREF #IMPLIED>
]>
<test i=i1><sub ir=i1></sub><sub i=i2></sub><sub ir=i2></sub></test>

attributes/attr-ids0

<!DOCTYPE test [
	<!ELEMENT test - - (sub+)>
	<!ELEMENT sub - - (#PCDATA)>
	<!ATTLIST test i ID #IMPLIED>
	<!ATTLIST sub i ID #IMPLIED ir IDREFS #IMPLIED>
]>
<test i=i1><sub ir=i1></sub><sub i=i2></sub><sub ir="i1 i2"></sub></test>

attributes/attr-number0

<!DOCTYPE test [
	<!ELEMENT test - - (#PCDATA)>
	<!ATTLIST test n NUMBER #REQUIRED>
]>
<test n=4321></test>

attributes/attr-numbers0

<!DOCTYPE test [
	<!ELEMENT test - - (#PCDATA)>
	<!ATTLIST test n NUMBERS #REQUIRED>
]>
<test n="4321 789"></test>

attributes/attr-nutoken0

<!DOCTYPE test [
	<!ELEMENT test - - (#PCDATA)>
	<!ATTLIST test n NUTOKEN #REQUIRED>
]>
<test n=43px></test>

attributes/attlist10

<!DOCTYPE test [
	<!ELEMENT test - - (#PCDATA)>
	<!ATTLIST test a1 CDATA #IMPLIED a2 CDATA #IMPLIED>
]>
<test a1="a1 value" a2="a2 value"></test>

attributes/attlist11

<!DOCTYPE test [
	<!ELEMENT test - - (#PCDATA)>
	<!ATTLIST test a1 CDATA #FIXED a1val>
]>
<test></test>

attributes/attlist12

<!DOCTYPE test [
	<!ELEMENT test - - (#PCDATA)>
	<!ATTLIST test a1 CDATA #FIXED "a1 val">
]>
<test></test>

attributes/attlist13

<!DOCTYPE test [
	<!ELEMENT test - - (#PCDATA)>
	<!ATTLIST test a1 CDATA "a1 val">
]>
<test></test>

attributes/attlist3

<!DOCTYPE test [
	<!ELEMENT test (#PCDATA)>
	<!ATTLIST test a (x|y|z) #REQUIRED>
]>
<test a="x"></test>

attributes/attlist4

<!DOCTYPE test [
	<!ELEMENT test (#PCDATA)>
	<!ATTLIST test a (x|y|z) #REQUIRED>
]>
<test a="y"></test>

attributes/attlist5

<!DOCTYPE test [
	<!ELEMENT test (#PCDATA)>
	<!ATTLIST test a (x|y|z) #REQUIRED>
]>
<test a="z"></test>

attributes/attlist7

<!DOCTYPE test [
	<!ELEMENT test (#PCDATA)>
	<!ATTLIST test a (x|y|z) #REQUIRED>
]>
<test x></test>

attributes/attlist15

<!DOCTYPE test [
	<!ELEMENT test - - (#PCDATA)>
	<!ATTLIST test a1 (abc|def|ghi) def>
]>
<test></test>

attributes/attlist16

<!DOCTYPE test [
	<!ELEMENT test - - (#PCDATA)>
	<!ATTLIST test a1 (abc|def|ghi) def>
]>
<test a1=abc></test>

attributes/attlist16d

<!DOCTYPE test [
	<!ELEMENT test - - (#PCDATA)>
	<!ATTLIST test a1 (abc|def|ghi) #fixed def>
]>
<test a1=Def></test>

attributes/attlist17

<!DOCTYPE test [
	<!ELEMENT test - - (test2)>
	<!ELEMENT test2 - - (#PCDATA)>
	<!ATTLIST (test|test2) a1 (abc|def|ghi) def>
]>
<test><test2 a1=abc></test2></test>

attributes/attlist18

<!DOCTYPE test [
	<!ELEMENT test - - (#PCDATA)>
	<!ATTLIST test a1 CDATA "">
]>
<test></test>

attributes/notation-attr0

<!doctype test [
	<!notation somenotation system "whatever">
	<!element test - - (#pcdata)>
	<!attlist test notationattr notation (somenotation) #implied>
]>
<test notationattr=somenotation>blabla</test>