E N D
Internal DTD • External DTD
Internal DTD • <?xml version="1.0"?> <!DOCTYPE note [ <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)> ]> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend</body> </note>
External DTD • <?xml version="1.0"?> • <!DOCTYPE note SYSTEM "note.dtd"> • <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
DTD Root Element • Element Ordering is Important in DTD • <!ELEMENT tutorial (#PCDATA)> • <!DOCTYPE tutorial SYSTEM "tutorial.dtd"><tutorial>This is an XML document</tutorial> • Not a valid document • <!DOCTYPE tutorial SYSTEM "tutorial.dtd"><text>This is an XML document</text>
* arbitrary instances • <!ELEMENT XXX (AAA , BBB)><!ELEMENT AAA (#PCDATA)><!ELEMENT BBB (#PCDATA)> • <!ELEMENT XXX (AAA* , BBB)><!ELEMENT AAA (#PCDATA)> <!ELEMENT BBB (#PCDATA)>
+ One or several • <!ELEMENT XXX (AAA+ , BBB)><!ELEMENT AAA (#PCDATA)><!ELEMENT BBB (#PCDATA)>
? – zero or one instance • <!ELEMENT XXX (AAA? , BBB)><!ELEMENT AAA (#PCDATA)> <!ELEMENT BBB (#PCDATA)>
|- one from many • <!ELEMENT XXX (AAA , BBB)><!ELEMENT AAA (CCC , DDD)><!ELEMENT BBB (CCC | DDD)><!ELEMENT CCC (#PCDATA)> <!ELEMENT DDD (#PCDATA)>
<!ELEMENT XXX (AAA+ , BBB+)><!ELEMENT AAA (BBB | CCC )<!ELEMENT XXX (AAA+ , BBB+)><!ELEMENT AAA (BBB | CCC ) <!ELEMENT BBB (#PCDATA | CCC )*><!ELEMENT CCC (#PCDATA)> <!DOCTYPE tutorial SYSTEM "tutorial.dtd"> <XXX> <AAA>Element: <CCC/> </AAA> <BBB> Element: <CCC/> </BBB> </XXX> wrong
<!ELEMENT attributes (#PCDATA)> <!ATTLIST attributes • aaa CDATA #REQUIRED bbb CDATA #IMPLIED>
NMTOKEN type can contain only letters, digits and point [ . ] , hyphen [ - ], underline [ _ ] and colon [ : ] • NMTOKENS – NMTOKEN plus white spaces • <!ELEMENT attributes (#PCDATA)><!ATTLIST attributes aaa CDATA #IMPLIED bbb NMTOKEN #REQUIRED ccc NMTOKENS #REQUIRED>
ID type can contain only characters permitted for NMTOKEN and must start with a letter. No element type may have more than one ID attribute specified. The value of an ID attribute must be unique between all values of all ID attributes.
<!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<!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 value of IDREF attribute must match the value of some ID attribute in the document. The value of IDREFS attribute can contain several references to elements with ID attribute separated with whitespaces.
<!ELEMENT XXX (AAA+ , BBB+, CCC+, DDD+)><!ELEMENT AAA (#PCDATA)><!ELEMENT BBB (#PCDATA)><!ELEMENT CCC (#PCDATA)><!ELEMENT DDD (#PCDATA)><!ATTLIST AAA mark ID #REQUIRED<!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>
<!ELEMENT XXX (AAA+, BBB+)><!ELEMENT AAA (#PCDATA)><!ELEMENT BBB (#PCDATA)><!ATTLIST AAA true ( yes | no ) #REQUIRED> <!ATTLIST BBB month (1|2|3|4|5|6|7|8|9|10|11|12) #IMPLIED> <!ELEMENT XXX (AAA+, BBB+)><!ELEMENT AAA (#PCDATA)><!ELEMENT BBB (#PCDATA)><!ATTLIST AAA true ( yes | no ) #REQUIRED> <!ATTLIST BBB month (1|2|3|4|5|6|7|8|9|10|11|12) #IMPLIED>
<!ELEMENT XXX (AAA+, BBB+)><!ELEMENT AAA (#PCDATA)> <!ELEMENT BBB (#PCDATA)> <!ATTLIST AAA true ( yes | no ) "yes"> <!ATTLIST BBB month NMTOKEN "1"> <!ELEMENT XXX (AAA+, BBB+)><!ELEMENT AAA (#PCDATA)> <!ELEMENT BBB (#PCDATA)> <!ATTLIST AAA true ( yes | no ) "yes"> <!ATTLIST BBB month NMTOKEN "1"> • The values of true are yes, no and yes. The values of month are 8, 2 and 1.:
<!ELEMENT XXX (AAA+)> <!ELEMENT AAA EMPTY> <!ATTLIST AAA true ( yes | no ) "yes"><!ELEMENT XXX (AAA+)> <!ELEMENT AAA EMPTY> <!ATTLIST AAA true ( yes | no ) "yes"> • An element can be defined EMPTY. In such a case it can contain only attributes but no text.