Tutorial DTD PDF Print E-mail
User Rating: / 1
PoorBest 
Saturday, 12 July 2008
HTML clipboard

1. Example 1
       An XML document is valid if it is associated with a type of document and it complies with the constraints set out therein. The document type definition must appear before the first element of the document. The name that follows the word DOCTYPE in defining document type must match the name of the root element.

     * <! ELEMENT tutorial (# PCDATA)>
       A document can include a single root element tutorial that can contain text

     * Valid
       <tutorial> This is an XML document </ tutorial>
       Document valid text

     *Valid
       <tutorial/>
       This document is also valid

     * Invalid

       <text> This is an XML document </ text>
       The root element does not conform to the specified DTD

2. Example 2
       One type of element has a content item when elements of this type must not include that element son (no data character), possibly separated by spaces.

      # <! ELEMENT XXX (AAA, BBB)>
         <! ELEMENT AAA (# PCDATA)>
         <! ELEMENT BBB (# PCDATA)>
       The root element XXX must specifically include an element AAA, followed by a BBB. The AAA and BBB can contain text, but no other element.

     * Valid
       <XXX>
      <AAA>Start</AAA>
      <BBB>End</BBB>
      </XXX>   

        Valid document containing text
     * Valid
       <XXX> <AAA/> <BBB/> </ XXX>
       This document is also valid

     *Invalid
       <XXX> <AAA/> ___ </ XXX>
       The BBB is absent

     * Invalid
       <XXX> <BBB/> <AAA/> </ XXX>
       The BBB must follow the element AAA

     * Invalid
       <XXX> <AAA/> <BBB/> <BBB/> </ XXX>
       The root element XXX can contain one element BBB

     * Invalid
       <XXX> Elements: <AAA/> <BBB/> </ XXX>
       The root element XXX shall contain no text

3. Example 3
       In a DTD, if an element name is followed by an asterisk [*], this element may be zero, one or more times.

     * <! ELEMENT XXX (* AAA, BBB)>
       <! ELEMENT AAA (# PCDATA)>
       <! ELEMENT BBB (# PCDATA)>
       The root element XXX may contain zero, one or more elements AAA, followed precisely an element BBB. The BBB must always be present

     * Valid
      <XXX> <AAA/> <BBB/> </ XXX>
       Document valid

     * Valid
       <XXX> <BBB/> </ XXX>
       Other valid document. The AAA is not mandatory

     * Valid
     <XXX> <AAA/> <AAA/> <AAA/> <AAA/> <AAA/> <AAA/> <AAA/> <BBB/> </ XXX>
     Several AAA elements may be included in the document

     * Not Valid
     <XXX> ___ </ XXX>
     The BBB is absent

     * Not Valid
     <XXX> <BBB/> <AAA/> </ XXX>
     The BBB must follow the element AAA

     * Not Valid
     <XXX> <AAA/> <AAA/> <AAA/> <AAA/> <BBB/> <AAA/> <AAA/> </ XXX>
     The AAA does not track the element BBB

4. Example 4
       In a DTD, if an element name is followed by a plus sign [+], this might be one or several times.

     * <! ELEMENT XXX (AAA +, BBB)>
      <! ELEMENT AAA (# PCDATA)>
      <! ELEMENT BBB (# PCDATA)>

      The root element XXX must contain one or more elements AAA, followed precisely an element BBB. The BBB must always be present

     * Valid
       <XXX> <AAA/> <BBB/> </ XXX>
       Document valid

     * Valid
       <XXX> <AAA/> <AAA/> <AAA/> <AAA/> <AAA/> <AAA/> <AAA/> <BBB/> </ XXX>
       Several AAA elements may be included in the document

     * Not Valid
       <XXX> ___ ___ </ XXX>
       The AAA and BBB are absent

     * Not Valid
       <XXX> ___ <BBB/> </ XXX>
       At least one element must be present AAA

     * Not Valid
       <XXX> <BBB/> <AAA/> </ XXX>
       The BBB must follow the element AAA

     * Not Valid
       <XXX> <AAA/> <AAA/> <AAA/> <AAA/> <BBB/> <AAA/> <AAA/> </ XXX>
       The AAA does not track the element BBB

5. Example 5
       In a DTD, if an element name is followed by a question mark [?], This element may be zero or once.
     * <! ELEMENT XXX (AAA?, BBB)>
       <! ELEMENT AAA (# PCDATA)>
       <! ELEMENT BBB (# PCDATA)>
       The root element XXX may contain an element AAA, followed precisely an element BBB. The BBB must always be present.

     * Valid
       <XXX> <AAA/> <BBB/> </ XXX>
       Document valid

     * Valid
       <XXX> <BBB/> </ XXX>
       The AAA is not mandatory

     * Not Valid
       <XXX> ___ </ XXX>
       The BBB is absent

     * Not Valid
       <XXX> <AAA/> <AAA/> <AAA/> <AAA/> <AAA/> <AAA/> <AAA/> <BBB/> </ XXX>
       An AAA maximum may be included in the document

     * Not Valid
       <XXX> <BBB/> <AAA/> </ XXX>
       The BBB must follow the element AAA

6. Example 6
       This example uses a combination of [+ *?]
     * <! ELEMENT XXX (AAA?, BBB +)>
       <! ELEMENT AAA (CCC?, DDD *)>
       <! ELEMENT BBB (CCC, DDD)>
       <! ELEMENT CCC (# PCDATA)>
       <! ELEMENT DDD (# PCDATA)>
       The root element XXX may contain an element AAA, followed by one or more elements BBB. The AAA may contain an element CCC and DDD several elements. The BBB must specifically contain an element CCC and a DDD

     # Valid
       <XXX>
        <AAA>
         <CCC/> <DDD/>
           </ AAA>
               <BBB>
              <CCC/> <DDD/>
            </ BBB>
       </ XXX>
      Document valid

    # Valid
      <XXX>
          <AAA/>
              <BBB>
            <CCC/> <DDD/>
         </ BBB>
      </ XXX>
     The son of element AAA is not mandatory

    # Valid
      <XXX>
          <BBB>
         <CCC/> <DDD/>
         </ BBB>
      </ XXX>
     The AAA may be omitted

    # Not Valid
     <XXX>
       <AAA/>
       <BBB/>
     </ XXX>
    The BBB must include the CCC and DDD

    # Not Valid
      <XXX>
          <AAA>
                       <CCC/> <CCC/>
                        <DDD/> <DDD/>
                </ AAA>
                <BBB>
                     <CCC/> <DDD/>
         </ BBB>
      </ XXX>
     The AAA may contain a maximum CCC

7. Example 7
       The [|] you can select an item from several elements.
     * <! ELEMENT XXX (AAA, BBB)>
       <! ELEMENT AAA (CCC, DDD)>
       <! ELEMENT BBB (CCC | DDD)>
       <! ELEMENT CCC (# PCDATA)>
       <! ELEMENT DDD (# PCDATA)>
       The root element XXX must contain an element AAA, followed by a BBB. The AAA must contain an element CCC, followed by a DDD. The BBB must contain an element CCC, is an element DDD

     * Valid
       <XXX>
<AAA>
<CCC/> <DDD/>
</AAA>
<BBB>
<CCC/>
</BBB>
       </XXX>
       Document valid

     * Valid
       <XXX>
<AAA>
<CCC/> <DDD/>
</AAA>
<BBB>
<DDD/>
</BBB>
      </XXX>
       Other valid document

     * Invalid
       <XXX>
<AAA>
<CCC/> <DDD/>
</AAA>
<BBB>
<CCC/> <DDD/>
</BBB>
       </XXX>
       The BBB can contain either a CCC is a DDD, but not both

     * Invalid
       <XXX>
<AAA>
<CCC/> <DDD/>
</AAA>
<BBB>
<DDD/>  <CCC/>
</BBB>
      </XXX>
       The BBB can contain either a CCC is a DDD, but not both

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
 
< Prev   Next >
School Joomla Templates and Joomla Tutorials