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 attributes/attr-entity1

Examples for attributes with declared value ENTITY

attributes/attr-entities0 attributes/attr-entities1

Examples for attributes with declared value ENTITIES

attributes/attr-id0 attributes/attr-ids0

Examples for attributes with declared value ID

attributes/attr-number0 attributes/attr-number1

Examples for attributes with declared value NUMBER

attributes/attr-numbers0 attributes/attr-numbers1

Examples for attributes with declared value NUMBERS

attributes/attr-nutoken0 attributes/attr-nutoken1

Examples for attributes with declared value NUTOKEN

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

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/attlist6 attributes/attlist7 attributes/attlist8

Basic example of enumerated values (using #REQUIRED defaulting semantics); attlist8 shows that 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/attlist15a attributes/attlist15b attributes/attlist16 attributes/attlist16d

Example 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 (attlist15a) or #FIXED (attlist15b) value, the declared default value must be among the permitted enumerated values; as attlist9, attlist16, attlist16a, and attlist16d show, any attribute value (CDATA, enumerated values, NAME or NMTOKEN declared value) can, but don'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 (ie. can be declared/specified in upper, lower, or mixed case by default)

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 attributes/notation-attr1 attributes/notation-attr4

Examples for attributes with declared value NOTATION

attributes/attr-name0

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

Result

<!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>

Result

<!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>

Result

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

attributes/attr-entity1

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

Result


"attr-entity1.sgm": line 6: element test: 'nonent': reference to undeclared entity

attributes/attr-entities0

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

Result

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

attributes/attr-entities1

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

Result


"attr-entities1.sgm": line 7: element test: 'nonent': reference to undeclared entity

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>

Result

<!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>

Result

<!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>

Result

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

attributes/attr-number1

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

Result


"attr-number1.sgm": line 5: element test: '4x': invalid NUMBER token

attributes/attr-numbers0

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

Result

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

attributes/attr-numbers1

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

Result


"attr-numbers1.sgm": line 5: element test: '4x': invalid NUMBER token

attributes/attr-nutoken0

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

Result

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

attributes/attr-nutoken1

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

Result


"attr-nutoken1.sgm": line 5: element 'test': '4321': invalid NUTOKEN token

attributes/attlist10

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

Result

<!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>

Result

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

attributes/attlist12

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

Result

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

attributes/attlist13

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

Result

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

attributes/attlist14

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

Result


"attlist14.sgm": line 5: fatal: element test: attribute a1: invalid value for fixed attribute

attributes/attlist3

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

Result

<!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>

Result

<!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>

Result

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

attributes/attlist6

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

Result


"attlist6.sgm": line 5: element test: attribute a: 'invalid': invalid value for attribute

attributes/attlist7

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

Result

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

attributes/attlist8

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

Result


"attlist8.sgm": line 5: fatal: 'bla': token not in token group for any attributes of element test

attributes/attlist15

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

Result

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

attributes/attlist15a

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

Result


"attlist15a.sgm": line 3: fatal: name token xyz: default value not in token list for attribute

attributes/attlist15b

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

Result


"attlist15b.sgm": line 3: fatal: name tokenxyz: fixed value not in token list for attribute

attributes/attlist16

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

Result

<!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>

Result

<!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>

Result

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

attributes/attlist18

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

Result

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

attributes/notation-attr0

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

Result

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

attributes/notation-attr1

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

Result


"notation-attr1.sgm": line 6: element test: attribute notationattr: 'nonotation': invalid notation name for attribute

attributes/notation-attr4

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

Result


"notation-attr4.sgm": line 4: 'nonotation': use of an undeclared notation in name group of permitted notation names