1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
***************************************************
***** .dtd (Document Type Definition)
***************************************************
* Including in XML
******************
<?xml version = "1.0" encoding = "UTF-8"?>
_
|<!DOCTYPE address SYSTEM "address.dtd">
|<!DOCTYPE address PUBLIC "URL/address.dtd">
_
....
*********************************
* Something like class definition
*********************************
<?xml version='1.0' encoding='UTF-8' ?>
<!ELEMENT name (first,midle,last)>
<!ELEMENT contact (address, phone)>
<!ELEMENT first (#PCDATA)>
<!ELEMENT middle (#PCDATA)>
<!ELEMENT last (#PCDATA)>
<!ELEMENT address (#PCDATA)>
<!ELEMENT phone (#PCDATA)>
*******************
* adding attributes
*******************
<!ATTLIST name type (current|past) #REQUIRED id ID #IMPLIED
<!ATTLIST mobile type CDATA #IMPLIED
name - Element name for which specifiying attributes
type,id - Attribute names
current|past - Possible values (enumeration type)
CDATA - String
ID - Name(letters,_) which UNIQUE for xml document
IDREF, IDREFS, ENTITY, ENTITIES, NMTOKEN, NMTOKENS
#REQUIRED - attribute is required
#IMPLIED - attribute isn't required
****************
* Optional nodes
****************
? Optional
+ Repeatable
* Optional and Repeatable
| OR
For example:
<!ELEMENT name(first,middle?,last)>
<!ELEMENT contact(phone|mobile,address)>
********
* Entity
********
** Something like #define, once defined in .dtd, then can be referenced from
** later in .dtd or .xml documents, for example author of dtd:
<!ENTITY dtd-author "Kain the Dragon">
** Referencing in .xml document
&dtd-authord
** Or more complex (list of elements)
<!ENTITY %person "name, contact">
<!ELEMENT Manager (%person;)>
<!ELEMENT Admin (%person;)>
** Or list of attributes
<!ATTLIST % name attrname datatype #use>
** Yes ATTLIST not ENTITY (only differs from ATTLIST with '%' symbol)
** Later may be used
<!ATTLIST Manager %name;>
** Including external file with entities
<!ENTITY % name SYSTEM "filename.dtd">
** or from web
<!ENTITY % name PUBLIC "http://URL">
*************
* Comentaries
*************
<!-- multiline comment -->
|