Download presentation
Presentation is loading. Please wait.
Published byAdrian Patterson Modified over 9 years ago
1
Chapter 4: Document Type Definitions
2
Chapter 4 Objectives Learn to create DTDs Validate an XML document against a DTD Use DTDs to create XML documents from multiple files
3
My First DTD <!DOCTYPE name [ ]> John Fitzgerald Johansen Doe
4
Preparing the Ground
5
What’s in a Name? <!DOCTYPE name [ ]> John Fitzgerald Johansen Doe
6
Try It Out What’s in a Name?
7
The Document Type Declaration System Identifiers
8
The Document Type Declaration Public Identifiers
9
Try It Out The External DTD
10
Using External DTD John Quincy Public
11
Anatomy of a DTD
12
Element Declarations Element declarations consist of three basic parts: The ELEMENT declaration The element name The element content model
13
Element Content Or
14
Sequences John Fitzgerald Johansen Doe
15
Choices
16
Combining Sequences and Choice Using Groups
17
Cardinality IndicatorDescription [none]As we have seen in all of our content models thus far, when no cardinality indicator is used, it indicates that the element must appear once and only once. This is the default behavior for elements used in content models. ?Indicates that the element may appear either once or not at all. +Indicates that the element may appear one or more times. *Indicates that the element may appear zero or more times.
18
Mixed Content
19
Mixed Content Jeff is a developer and author for Beginning XML 4 th edition. Jeff loves XML!
20
Empty and Any
21
Try It Out “Making Contact” Part 1 “Making Contact” Part 2
22
Cardinalities How would you: guarantee that a contact had a least one first name? specify that a list of contacts could have many contacts on it?
23
Attribute Declarations An ATTLIST declaration consists of three basic parts: *The ATTLIST keyword *The associated element’s name *The list of declared attributes *The attribute name *The attribute type *The attribute value declaration source CDATA #IMPLIED
24
Attribute Types TypeDescription CDATAIndicates that the attribute value is character data IDIndicates that the attribute value uniquely identifies the containing element IDREFIndicates that the attribute value is a reference, by ID, to a uniquely identifiable element IDREFSIndicates that the attribute value is a whitespace-separated list of IDREF values ENTITYIndicates that the attribute value is a reference to an external unparsed entity (we will learn more about entities later). The unparsed entity might be an image file or some other external resource such as an MP3 or some other binary file ENTITIESIndicates that the attribute value is a whitespace-separated list of ENTITY values NMTOKENIndicates that the attribute value is a name token. An NMTOKEN is a string of character data consisting of standard name characters NMTOKENSIndicates that the attribute value is a whitespace-separated list of NMTOKEN values Enumerated List Apart from using the default types, you can also declare an enumerated list of possible values for the attribute
25
Attribute Value Declarations Has a default value Has a fixed value Is required Is implied
26
Specifying Multiple Attributes <!ATTLIST contacts version CDATA #FIXED “1.0” source CDATA #IMPLIED>
27
Try It Out “Making Contact” Part 3
28
Entities Jeff is a developer & author for Beginning XML 4th edition © 2006 Wiley Publishing. Jeff loves XML! *Built-in entities *Character entities *General entities *Parameter entities
29
Built-in Entities &—the & character <—the < character >—the > character '—the ‘ character "—the “ character Jeff is a developer & author for Beginning XML 4th edition © 2006 Wiley Publishing. Jeff loves XML!
30
Character Entities ©the © character
31
General Entities Internal External or <!ENTITY jeff-description PUBLIC "-//Beginning XML//Jeff Description//EN" "jeff.txt"> Referencing &jeff-description;
32
Parameter Entities Internal External: SYSTEM or PUBLIC or <!ENTITY % NameDeclarations PUBLIC "-//Beginning XML 4E//DTD External module//EN" "name4.dtd"> Referencing Examples %NameDeclarations;
33
Developing DTDs For example, the following is valid: The following is not valid: <!ATTLIST contacts source CDATA #IMPLIED>
34
DTD Limitations Some limitations of DTDs include: Differences between DTD syntax and XML syntax Poor support for XML namespaces Poor data typing Limited content model descriptions
35
Try It Out “Making Contact” Part 3 “Making Contact” Part 4 “Making Contact” Part 5
36
Other Validating Tools XSD Some of the restrictions with DTDs are resolved using XML Schema Definitions. Use XML syntax. More powerful than DTD files Example: http://www.uniprot.org/docs/uniprot.xsd RELAX NG Simple and easy to learn It supports XML Schema datatypes Two syntaxes: XML and compact syntax
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.