03 - XML - DTD
Transcript of 03 - XML - DTD
-
8/3/2019 03 - XML - DTD
1/29
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
eXtensible Markup Language
Document Type Definitions (DTDs)
eXtensible Markup Language Phan Vo Minh Thang
-
8/3/2019 03 - XML - DTD
2/29
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
-
8/3/2019 03 - XML - DTD
3/29
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
-
8/3/2019 03 - XML - DTD
4/29
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
-
8/3/2019 03 - XML - DTD
5/29
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
XML Lectures Notes Document Type Definition
-
8/3/2019 03 - XML - DTD
6/29
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
XML Lectures Notes Document Type Definition
-
8/3/2019 03 - XML - DTD
7/29
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
XML Lectures Notes Document Type Definition
-
8/3/2019 03 - XML - DTD
8/29
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
XML Lectures Notes Document Type Definition
-
8/3/2019 03 - XML - DTD
9/29
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
-
8/3/2019 03 - XML - DTD
10/29
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
< e s o 0 > < ate a > ectu es otes ocu e t ype e t o
Element Declaration
DTD is a mechanism to describe every object (element,attribute,) that can appear in an XML document
Element Declaration
Content specification specifies what children the element may or musthave in what order
Parentheses are used to group elements in content specification
-
8/3/2019 03 - XML - DTD
11/29
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
yp
Special Keywords in Content Model
Special Keywords in Content Model #PCDATA: parsed character data (text)
CDATA sections appear anywhere #PCDATA appears
EMPTY: empty element
ANY: can contain any other elements declared in the DTD
(including mixed content, child elements)
Mixed Content
Element contents that have #PCDATA Element Content
Element contents that contain only elements
-
8/3/2019 03 - XML - DTD
12/29
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
yp
The Secret of +, *, ?
+, *, ?: Occurrence indicators No occurrence indicator: appear once and only once
+: appear one or several times
*: appear zero or more times
?: appear once or not at all
Example
-
8/3/2019 03 - XML - DTD
13/29
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
The Secret of , |
, | : Connectors , : Elements must appear in the same order
| : Only one element must appear
Examples
Mixed Content: Components must always separated by a |,and the model must repeat
PCDATA must be the first child in the list
-
8/3/2019 03 - XML - DTD
14/29
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
More Examples
footnote | emphasize | date)* >
-
8/3/2019 03 - XML - DTD
15/29
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
Attribute Declaration
Attribute Declaration
value>
preferred (true|false) false>
Can appear anywhere in the DTDBest to list attributes immediately after the element declaration
-
8/3/2019 03 - XML - DTD
16/29
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
Attribute Type
CDATA: String
ID: Identifier unique in the document
IDREF: Value of an ID
IDREFS: List of IDREF separated by space
ENTITY: Name of an external entity
ENTITIES: List of ENTITY
NMTOKEN: Word without spaces
NMTOKENS: List of NMTOKEN
Enumerated-type list: Closed list of NMTOKEN separatedby |
Notation: name of a notation declared in the DTD
-
8/3/2019 03 - XML - DTD
17/29
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
Attribute Types (Cont.)
CDATA Any text string acceptable in a well-formed XML attribute value
The most general attribute type
Can be used for prices, URIs, email addresses, citations
NMTOKEN (named token)
Consist of the same characters as an XML name, but any allowed
characters can be the first character in a name token
12, .cshrc
NMTOKENS
one ore more XML name tokens separated by whitespace
Katand the Kings
-
8/3/2019 03 - XML - DTD
18/29
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
Attribute Types (Cont.)
Enumeration A list of all possible values for the attribute, separated by |
Each possible value must be an XML name token
ID assign unique identifiers to elements
An XML name that is unique within the XML document (no other IDtype attribute in the document can have the same value)
Each element must have no more than one ID type attribute
-
8/3/2019 03 - XML - DTD
19/29
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
Attribute Types (Cont.)
IDREF Refer to the ID type attribute of some element in the document
Used to establish relationships between elements when simple
containment won't suffice
Do not constrain the person attribute of the team_member elementto match only employee IDs or constrain the project_id attribute ofthe assignment element to match only project IDs
IDREFS
Contain a whitespace-separated list of XML names, each of which
must be the ID of an element in the document
-
8/3/2019 03 - XML - DTD
20/29
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
Attribute Types (Cont.)
ENTITY Contain the name of an unparsed entity declared elsewhere in
DTD
ENTITIES
Contain the name of one ore more unparsed entities declaredelsewhere in the DTD, separated by whitespace
-
8/3/2019 03 - XML - DTD
21/29
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
Attribute Types (Cont.)
NOTATION Contain the name of a notation declared in the document's DTD
It could be used to associate types with particular elements, as
well as limiting the types associated with the element
-
8/3/2019 03 - XML - DTD
22/29
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
Default Value
#REQUIRED The attribute is required. Each instance of the element must
provide a value for the attribute
No default value is provided
#IMPLIED
The attribute is optional. Each instance of the element may or maynot provide a value for the attribute
No default value is provided
-
8/3/2019 03 - XML - DTD
23/29
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
Default Value (Cont.)
#FIXED (follow by a value) The attribute value is constant and immutable. The attribute has
the specified value regardless of whether the attribute is explicitlynoted on an individual instance of the element
If it is included, it must have the specified value
-
8/3/2019 03 - XML - DTD
24/29
-
8/3/2019 03 - XML - DTD
25/29
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
Limitation of DTD
Limitations of DTD Content is limited to textual
Difficult to put in repetition constraints
DTD does not use XML syntax
DTD does not say the following
What the root element of the document is
How many of instances of each kind of element appear in thedocument
What the character data inside the elements looks like
The semantic meaning of an element
A DTD never says anything about the length, structure, meaning,allowed values, or other aspects of the text content of an element
-
8/3/2019 03 - XML - DTD
26/29
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
Advanced DTD
General Entity Declaration
External Parsed General Entities
External Unparsed Entities and Notations
Parameter Entities
Conditional Inclusion
-
8/3/2019 03 - XML - DTD
27/29
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
Validation
A validating parser compares a document to its DTD andlists any places where the document differs from theconstraints specified in the DTD
The parser can decide what it wants to do about any violationsA validity error is not necessarily a fatal error
Validation is an optional step in processing XML
Everything not permitted in the DTD is forbidden
-
8/3/2019 03 - XML - DTD
28/29
-
8/3/2019 03 - XML - DTD
29/29
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
Info
Course name:Special Selected Topic in
Information System Section: Document Type Definitions (DTDs)
Number of slides: 29
Updated date: 12/02/2006 Contact: Mr.Phan Vo Minh Thang