8. Example 8
From the text can be inserted with the elements.
* <!ELEMENT XXX (AAA+ , BBB+)>
<!ELEMENT AAA (BBB | CCC )>
<!ELEMENT BBB (#PCDATA | CCC )*>
<!ELEMENT CCC (#PCDATA)>
The AAA can contain either a BBB, is a CCC. However, the element BBB may contain any combination of text and elements CCC. * Valid
<XXX>
<AAA>
<CCC>Precisely one element.</CCC>
</AAA>
<AAA>
<BBB>
<CCC/>
<CCC/>
<CCC/>
</BBB>
</AAA>
<BBB/>
<BBB>
Here<CCC/> combination of elements <CCC/> and text<CCC/>.
</BBB>
<BBB>
Only text
</BBB>
</XXX>
Document valid operator several possibilities
* Invalid
<XXX>
<AAA>
Element : <CCC/>
</AAA>
<BBB>
Element : <CCC/>
</BBB>
</XXX>
The AAA can not contain text
9. Example 9
The attributes used to associate name-value pairs to the elements. The specifications of attributes that can not be included in the tags start and tags elements empty. The declaration begins with ATTLIST follow after the name of the element to which attributes are attached and, finally, the definition of individual attributes.
* <!ELEMENT attributes (#PCDATA)>
<!ATTLIST attributes
aaa CDATA #REQUIRED
bbb CDATA #IMPLIED>
An attribute type CDATA may contain any character, if it respects the constraints of form. The required attribute must always be present, while the implicit attribute is optional.
* Valid
<attributes aaa="#d1" bbb="*~*">
Text
</attributes>
The type CDATA attribute may contain any character respecting the constraints of form
* Valid
<attributes bbb="$25" aaa="13%">
Text
</attributes>
The order of attributes does not matter
* Valid
<attributes aaa="#d1" />
The bbb attribute may be omitted, since it is implicit
*Invalid
<attributes ___ bbb="X24"/>
The aaa attribute is mandatory, it must be always present
10. Example 10
An attribute type CDATA may contain any character, if it respects the constraints of form. The attributes type NMTOKEN may contain only letters, numbers, a point [. ], A dash [-], an underscore [_] and a colon [:]. The attributes type NMTOKENS may contain the same characteristics as attributes type NMTOKEN, plus blanks. For white space, means one or more spaces, carriage returns, line breaks or tabs.
* <!ELEMENT attributes (#PCDATA)>
<!ATTLIST attributes
aaa CDATA #IMPLIED
bbb NMTOKEN #REQUIRED
ccc NMTOKENS #REQUIRED>
The attributes bbb ccc and must always be present, while the attribute is optional aaa
* Valid
<attributes aaa="#d1" bbb="a1:12" ccc=" 3.4 div -4"/>
All the required attributes are present and the type of their value is correct
* Valid
<attributes bbb="a1:12"
ccc="3.4
div
-4"/>
All the required attributes are present and the type of their value is correct
*Invalid
<attributes aaa="#d1" bbb="#d1" ccc="#d1"/>
The character # is prohibited in the attributes of type NMTOKEN and NMTOKENS
*Invalid
<attributes bbb="A B C" ccc="A B C"/>
The space is prohibited in the attributes of type NMTOKEN
11. Example 11
The value of an attribute of type ID may be set up only character allowed for the type NMTOKEN and must begin with a letter. One type of element can not have several attributes of type ID. The value of an attribute of type ID must be unique compared to all the values of all attributes of type ID.
* <!ELEMENT XXX (AAA+ , BBB+ , CCC+)>
<!ELEMENT AAA (#PCDATA)>
<!ELEMENT BBB (#PCDATA)>
<!ELEMENT CCC (#PCDATA)>
<!ATTLIST AAA
id ID #REQUIRED>
<!ATTLIST BBB
code ID #IMPLIED
list NMTOKEN #IMPLIED>
<!ATTLIST CCC
X ID #REQUIRED
Y NMTOKEN #IMPLIED>
The attributes id, and X code that uniquely identifies their element
* Valid
<XXX>
<AAA id="a1"/>
<AAA id="a2"/>
<AAA id="a3"/>
<BBB code="QWQ-123-14-6" list="14:5"/>
<CCC X="zero" Y="16" />
</XXX>
All values are unique ID
* Valid
<XXX>
<AAA id="L12"/>
<BBB code="QW" list="L12"/>
<CCC X="x-0" Y="QW" />
<CCC X="x-1" Y="QW" />
</XXX>
The attributes list and Y are NMTOKEN type, and no type ID. They may therefore have the same value as the attributes ID or the same value in several elements
*Invalid
<XXX>
<AAA id="L12"/>
<BBB code="#QW" list="L12"/>
<CCC X="12" Y="QW" />
</XXX>
The ID attribute does not begin with a number or contain a character for the type NMTOKEN
*Invalid
<XXX>
<AAA id="L12"/>
<BBB code="QW" list="L12"/>
<CCC X="ZA" Y="QW" />
<CCC X="ZA" Y="QW" />
</XXX>
The ID attribute must include a unique value
*Invalid
<XXX>
<AAA id="L12"/>
<BBB code="QW" list="L12"/>
<CCC X="L12" Y="QW" />
</XXX>
The ID attribute must include a unique value. The attributes id and X are both type ID
12. Example 12
The value of the attribute IDREF must match that of one of the attributes ID present in the document. The value of the attribute IDREFS may contain several references to elements with an attribute ID, separated by white space.
* <!ELEMENT XXX (AAA+ , BBB+, CCC+, DDD+)>
<!ELEMENT AAA (#PCDATA)>
<!ELEMENT BBB (#PCDATA)>
<!ELEMENT CCC (#PCDATA)>
<!ELEMENT DDD (#PCDATA)>
<!ATTLIST AAA
mark ID #REQUIRED>
<!ATTLIST BBB
id ID #REQUIRED>
<!ATTLIST CCC
ref IDREF #REQUIRED>
<!ATTLIST DDD
ref IDREFS #REQUIRED>
The attributes id and mark uniquely identify their element. The attributes ref refer to these elements
* Valid
<XXX>
<AAA mark="a1"/>
<AAA mark="a2"/>
<AAA mark="a3"/>
<BBB id="b001" />
<CCC ref="a3" />
<DDD ref="a1 b001 a2" />
</XXX>
All values attributes are unique ID and all the attributes and IDREF IDREFS point to elements with attributes appropriate ID
*Invalid
<XXX>
<AAA mark="a1"/>
<AAA mark="a2"/>
<BBB id="b01" />
<CCC ref="a3" />
<DDD ref="a1 b001 a2" />
</XXX>
There is no ID attribute with a3 or as a value b001
*Invalid
<XXX>
<AAA mark="a1"/>
<AAA mark="a2"/>
<AAA mark="a3"/>
<BBB id="b001" />
<CCC ref="a1 b001 a2" />
<DDD ref="a1 b001 a2" />
</XXX>
The ref attribute of the element is CCC type IDREF. It may contain only one reference
13. Example 13
The values of attributes allowed can be defined in the DTD.
* <!ELEMENT XXX (AAA+, BBB+)>
<!ELEMENT AAA (#PCDATA)>
<!ELEMENT BBB (#PCDATA)>
<!ATTLIST AAA
true(yes | no)#REQUIRED>
<!ATTLIST BBB
months(1|2|3|4|5|6|7|8|9|10|11|12) #IMPLIED>
This DTD defines precisely the values
* Valid
<XXX>
<AAA true="yes"/>
<AAA true="no"/>
<AAA true="yes"/>
<BBB months="8" />
<BBB months="2" />
<BBB months="12" />
</XXX>
All values are defined in the DTD
*Invalid
<XXX>
<AAA true="yes"/>
<AAA true="no"/>
<AAA true="maybe"/>
<BBB months="8" />
<BBB months="2" />
<BBB months="16" />
</XXX>
The true attribute can not be "maybe" as a value, and attribute months can not have "16" as a value
14. Example 14
If an attribute is implicit, a default may be provided if the attribute is not used.
* <!ELEMENT XXX (AAA+, BBB+)>
<!ELEMENT AAA (#PCDATA)>
<!ELEMENT BBB (#PCDATA)>
<!ATTLIST AAA
yes(yes | no) "yes">
<!ATTLIST BBB
months NMTOKEN "1">
Both attributes are implicit. Their default is defined
* Valid
<XXX>
<AAA true="yes"/>
<AAA true="no"/>
<AAA/>
<BBB months="8" />
<BBB months="2" />
<BBB/>
</XXX>
Different values of the attribute is true yes, no and yes. Different values of the attribute are 8 months, 2 and 1
15. Example 15
An element can be defined as EMPTY. In this case, it may only contain attributes, but no text.
* <!ELEMENT XXX (AAA+)>
<!ELEMENT AAA EMPTY>
<!ATTLIST AAA
true(yes | no) "yes">
The AAA may contain only attributes, but no text
* Valid
<XXX>
<AAA true="yes"/>
<AAA true="no"></AAA>
</XXX>
These two forms are permitted. In the second case, the end tag must immediately follow the starting tag
*Invalid
<XXX>
<AAA true="yes"/>
<AAA true="no"></AAA>
<AAA> </AAA>
<AAA>Hi !</AAA>
</XXX>
The AAA does not contain text, and the starting tag must be closed immediately