SlideShare a Scribd company logo
DTD
Introduction
• Stands for Document Type Definition
• Allows to create rules for the elements within
your XML documents
• So, for an XML document to be well-formed, it
needs to use correct XML syntax, and it needs to
conform to its DTD or schema
• Is declared at the top of your XML document
• The actual contents of the DTD can be included
within your XML document or included in
another .dtd document
Example DTD
DTD <!DOCTYPE>
• DTD can either be
– internal (written into the same document that it's
being used in)
– external (located in another document).
• DTD is declared at the top of your XML
document using the !DOCTYPE declaration.
The basic syntax is:
DTD Variations
• <!DOCTYPE rootname [DTD]>
• <!DOCTYPE rootname SYSTEM URL>
• The keyword SYSTEM indicates that it's a
private DTD (not for public distribution)
• DTD is defined in a document located at the
URL
• <!DOCTYPE rootname SYSTEM URL [DTD]>
• The keyword SYSTEM indicates that it's a
private DTD (not for public distribution)
• The presence of URL and [DTD] together
indicates that this is both an external and
internal DTD (part of the DTD is defined in a
document located at the URL, the other part is
defined within the XML document)
Example
Internal DTD
• Whether we use an external or internal DTD,
the actual syntax for the DTD is the same
• Same code could just as easily be part of an
internal DTD or an external one
• The only difference between internal and
external is in the way it's declared with
DOCTYPE
Example
External DTD
• Is one that resides in a separate document
• To use the external DTD, we need to link to it
from our XML document by providing the URI
of the DTD file
• This URI is in the form of a URL
• The URL can point to a local file using a
relative reference, or a remote one (eg, using
HTTP)
Example
DTD
Combined DTD
• Can use both an internal DTD and an external
one at the same time
• This could be useful if you need to adhere to a
common DTD, but also need to define your
own definitions locally
Example
DTD
DTD Elements
• Creating a DTD is quite straight forward
• To define an element in your DTD, we use the
<!ELEMENT> declaration
• The actual contents of your <!ELEMENT>
declaration will depend on the syntax rules
you need to apply to your element
Basic Syntax
• <!ELEMENT element_name content_model>
– element_name is the name of the element
– content_model could indicate a specific rule, data
or another element
• If it specifies a rule, it will be set to either ANY or
EMPTY
• If specifies data or another element, the data
type/element name needs to be surrounded by
brackets (i.e. (tutorial) or (#PCDATA))
Plain Text
• If an element should contain plain text, you define the
element using #PCDATA.
• PCDATA stands for Parsed Character Data
• Syntax:
– <!ELEMENT element_name (#PCDATA)>
• Example:
– <!ELEMENT name (#PCDATA)>
• The above line in your DTD allows the name element to
contain non-markup data in your XML document:
– <name>XML Tutorial</name>
Unrestricted Elements
• If it doesn't matter what element contains, we
can create an element using the
content_model of ANY
• Doing this removes all syntax checking, so we
should avoid using this if possible
• Syntax:
– <!ELEMENT element_name ANY>
• Example:
– <!ELEMENT tutorials ANY>
Empty Elements
• Empty element is one without a closing tag.
• For example, in HTML, the <br /> and <img /> tags are
empty elements.
• Here's how you define an empty element:
• Syntax:
– <!ELEMENT element_name EMPTY>
• Example:
– <!ELEMENT header EMPTY>
• The above line in your DTD defines the following empty
element for your XML document:
– <header />
Child Elements
• Can specify that an element must contain
another element, by providing the name of
the element it must contain.
• Here's how you do that:
• Syntax:
– <!ELEMENT element_name
(child_element_name)>
• Example:
– <!ELEMENT tutorials (tutorial)>
• The above line in DTD allows the tutorials
element to contain one instance of the
tutorial element in XML document:
Multiple Child Elements (Sequences)
• You can also provide a comma separated list of
elements if it needs to contain more than one element.
This is referred to as a sequence. The XML document
must contain the tags in the same order that they're
specified in the sequence.
• Syntax:
<!ELEMENT element_name (child_element_name,
child_element_name,...)>
• Example:
<!ELEMENT tutorial (name, author)>
• The above line in DTD allows the tutorial
element to contain one instance of the name
element and one instance of the author
element in XML document:
DTD Element Operators
• Are used to specify the number the times the
child elements can be used inside parents
elements
Zero or More
• To allow zero or more of the same child
element, use an asterisk (*)
• Syntax:
<!ELEMENT element_name
(child_element_name*)>
• Example:
<!ELEMENT tutorials (tutorial*)>
One or More
• To allow one or more of the same child
element, use a plus sign (+):
• Syntax:
<!ELEMENT element_name
(child_element_name+)>
• Example:
<!ELEMENT tutorials (tutorial+)>
Zero or One
• To allow either zero or one of the same child
element, use a question mark (?):
• Syntax:
<!ELEMENT element_name
(child_element_name?)>
• Example:
<!ELEMENT tutorials (tutorial?)>
Choices
• Can define a choice between one or another
element by using the pipe (|) operator.
• Syntax:
<!ELEMENT element_name (choice_1 | choice_2
| choice_3)>
• For example, if the tutorial element requires a
child called either name, title, or subject (but only
one of these)
<!ELEMENT tutorial (name | title | subject)>
DTD Operators with Sequences
• Can apply any of the DTD operators to a
sequence:
• Syntax:
<!ELEMENT element_name
(child_element_name dtd_operator,
child_element_name dtd_operator,...)>
• Example:
<!ELEMENT tutorial (name+, author?)>
DTD Attributes
• Just as we need to define all elements in your
DTD, we also need to define any attributes
they use.
• Use the <!ATTLIST> declaration to define
attributes
• Single <!ATTLIST> declaration to declare all
attributes for a given element
• Syntax
• Example
DTD Attribute Default Values

More Related Content

PDF
Xml schema
PPTX
html-table
PPTX
PPTX
Images and Tables in HTML
PDF
ORM in Django
PPTX
Html images syntax
Xml schema
html-table
Images and Tables in HTML
ORM in Django
Html images syntax

What's hot (20)

PPTX
HTML: Tables and Forms
PDF
JavaScript - Chapter 12 - Document Object Model
PPTX
HTML/HTML5
PPT
XML and DTD
PPTX
Html images
PPTX
Web html table tags
PPTX
XML, DTD & XSD Overview
PDF
CSS Day: CSS Grid Layout
PPT
Introduction to XML
PDF
Internationalization
PPT
Javascript arrays
PPT
Abstract class in java
PPT
Javascript
PPTX
Html links
PPT
XML Schema
PPTX
Javascript functions
PPT
Java awt
PPTX
Chapter 05 classes and objects
PPTX
HTML5 audio & video
HTML: Tables and Forms
JavaScript - Chapter 12 - Document Object Model
HTML/HTML5
XML and DTD
Html images
Web html table tags
XML, DTD & XSD Overview
CSS Day: CSS Grid Layout
Introduction to XML
Internationalization
Javascript arrays
Abstract class in java
Javascript
Html links
XML Schema
Javascript functions
Java awt
Chapter 05 classes and objects
HTML5 audio & video
Ad

Similar to DTD (20)

PPTX
Unit iv xml
PPTX
It8074 soa-unit i
PPTX
XML DTD DOCUMENT TYPE DEFINITION
PDF
it8074-soa-uniti-.pdf
PPTX
It8074 soa-unit i
PPTX
DTD1.pptx
PPTX
Web Technology Part 4
PDF
II UNIT PPT NOTES.pdf this is the data structures
PPTX
Web Security Extensible Markup Language.pptx
PPT
2-DTD.ppt
PPTX
Xml dtd
PDF
Xml 20111006 hurd
PDF
Xml
PPTX
Document type definition
PDF
Web Technologies Unit 2 Print.pdf
PPTX
XML's validation - DTD
PPTX
distributed system concerned lab sessions
PPT
web program-Extended MARKUP Language XML.ppt
Unit iv xml
It8074 soa-unit i
XML DTD DOCUMENT TYPE DEFINITION
it8074-soa-uniti-.pdf
It8074 soa-unit i
DTD1.pptx
Web Technology Part 4
II UNIT PPT NOTES.pdf this is the data structures
Web Security Extensible Markup Language.pptx
2-DTD.ppt
Xml dtd
Xml 20111006 hurd
Xml
Document type definition
Web Technologies Unit 2 Print.pdf
XML's validation - DTD
distributed system concerned lab sessions
web program-Extended MARKUP Language XML.ppt
Ad

More from Kamal Acharya (20)

PPTX
Programming the basic computer
PPTX
Computer Arithmetic
PPTX
Introduction to Computer Security
PPTX
Session and Cookies
PPTX
Functions in php
PPTX
Web forms in php
PPTX
Making decision and repeating in PHP
PPTX
Working with arrays in php
PPTX
Text and Numbers (Data Types)in PHP
PPTX
Introduction to PHP
PPTX
Capacity Planning of Data Warehousing
PPTX
Data Warehousing
PPTX
Search Engines
PPTX
Web Mining
PPTX
Information Privacy and Data Mining
PPTX
Cluster Analysis
PPTX
Association Analysis in Data Mining
PPTX
Classification techniques in data mining
PPTX
Data Preprocessing
PPTX
Introduction to Data Mining and Data Warehousing
Programming the basic computer
Computer Arithmetic
Introduction to Computer Security
Session and Cookies
Functions in php
Web forms in php
Making decision and repeating in PHP
Working with arrays in php
Text and Numbers (Data Types)in PHP
Introduction to PHP
Capacity Planning of Data Warehousing
Data Warehousing
Search Engines
Web Mining
Information Privacy and Data Mining
Cluster Analysis
Association Analysis in Data Mining
Classification techniques in data mining
Data Preprocessing
Introduction to Data Mining and Data Warehousing

Recently uploaded (20)

PDF
01-Introduction-to-Information-Management.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Complications of Minimal Access Surgery at WLH
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Institutional Correction lecture only . . .
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Cell Structure & Organelles in detailed.
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
01-Introduction-to-Information-Management.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
Supply Chain Operations Speaking Notes -ICLT Program
PPH.pptx obstetrics and gynecology in nursing
O5-L3 Freight Transport Ops (International) V1.pdf
Complications of Minimal Access Surgery at WLH
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Institutional Correction lecture only . . .
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
TR - Agricultural Crops Production NC III.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Cell Structure & Organelles in detailed.
Final Presentation General Medicine 03-08-2024.pptx
Anesthesia in Laparoscopic Surgery in India
human mycosis Human fungal infections are called human mycosis..pptx
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...

DTD

  • 1. DTD
  • 2. Introduction • Stands for Document Type Definition • Allows to create rules for the elements within your XML documents • So, for an XML document to be well-formed, it needs to use correct XML syntax, and it needs to conform to its DTD or schema • Is declared at the top of your XML document • The actual contents of the DTD can be included within your XML document or included in another .dtd document
  • 4. DTD <!DOCTYPE> • DTD can either be – internal (written into the same document that it's being used in) – external (located in another document). • DTD is declared at the top of your XML document using the !DOCTYPE declaration. The basic syntax is:
  • 6. • <!DOCTYPE rootname SYSTEM URL> • The keyword SYSTEM indicates that it's a private DTD (not for public distribution) • DTD is defined in a document located at the URL
  • 7. • <!DOCTYPE rootname SYSTEM URL [DTD]> • The keyword SYSTEM indicates that it's a private DTD (not for public distribution) • The presence of URL and [DTD] together indicates that this is both an external and internal DTD (part of the DTD is defined in a document located at the URL, the other part is defined within the XML document)
  • 9. Internal DTD • Whether we use an external or internal DTD, the actual syntax for the DTD is the same • Same code could just as easily be part of an internal DTD or an external one • The only difference between internal and external is in the way it's declared with DOCTYPE
  • 11. External DTD • Is one that resides in a separate document • To use the external DTD, we need to link to it from our XML document by providing the URI of the DTD file • This URI is in the form of a URL • The URL can point to a local file using a relative reference, or a remote one (eg, using HTTP)
  • 14. Combined DTD • Can use both an internal DTD and an external one at the same time • This could be useful if you need to adhere to a common DTD, but also need to define your own definitions locally
  • 17. DTD Elements • Creating a DTD is quite straight forward • To define an element in your DTD, we use the <!ELEMENT> declaration • The actual contents of your <!ELEMENT> declaration will depend on the syntax rules you need to apply to your element
  • 18. Basic Syntax • <!ELEMENT element_name content_model> – element_name is the name of the element – content_model could indicate a specific rule, data or another element • If it specifies a rule, it will be set to either ANY or EMPTY • If specifies data or another element, the data type/element name needs to be surrounded by brackets (i.e. (tutorial) or (#PCDATA))
  • 19. Plain Text • If an element should contain plain text, you define the element using #PCDATA. • PCDATA stands for Parsed Character Data • Syntax: – <!ELEMENT element_name (#PCDATA)> • Example: – <!ELEMENT name (#PCDATA)> • The above line in your DTD allows the name element to contain non-markup data in your XML document: – <name>XML Tutorial</name>
  • 20. Unrestricted Elements • If it doesn't matter what element contains, we can create an element using the content_model of ANY • Doing this removes all syntax checking, so we should avoid using this if possible • Syntax: – <!ELEMENT element_name ANY> • Example: – <!ELEMENT tutorials ANY>
  • 21. Empty Elements • Empty element is one without a closing tag. • For example, in HTML, the <br /> and <img /> tags are empty elements. • Here's how you define an empty element: • Syntax: – <!ELEMENT element_name EMPTY> • Example: – <!ELEMENT header EMPTY> • The above line in your DTD defines the following empty element for your XML document: – <header />
  • 22. Child Elements • Can specify that an element must contain another element, by providing the name of the element it must contain. • Here's how you do that: • Syntax: – <!ELEMENT element_name (child_element_name)> • Example: – <!ELEMENT tutorials (tutorial)>
  • 23. • The above line in DTD allows the tutorials element to contain one instance of the tutorial element in XML document:
  • 24. Multiple Child Elements (Sequences) • You can also provide a comma separated list of elements if it needs to contain more than one element. This is referred to as a sequence. The XML document must contain the tags in the same order that they're specified in the sequence. • Syntax: <!ELEMENT element_name (child_element_name, child_element_name,...)> • Example: <!ELEMENT tutorial (name, author)>
  • 25. • The above line in DTD allows the tutorial element to contain one instance of the name element and one instance of the author element in XML document:
  • 26. DTD Element Operators • Are used to specify the number the times the child elements can be used inside parents elements
  • 27. Zero or More • To allow zero or more of the same child element, use an asterisk (*) • Syntax: <!ELEMENT element_name (child_element_name*)> • Example: <!ELEMENT tutorials (tutorial*)>
  • 28. One or More • To allow one or more of the same child element, use a plus sign (+): • Syntax: <!ELEMENT element_name (child_element_name+)> • Example: <!ELEMENT tutorials (tutorial+)>
  • 29. Zero or One • To allow either zero or one of the same child element, use a question mark (?): • Syntax: <!ELEMENT element_name (child_element_name?)> • Example: <!ELEMENT tutorials (tutorial?)>
  • 30. Choices • Can define a choice between one or another element by using the pipe (|) operator. • Syntax: <!ELEMENT element_name (choice_1 | choice_2 | choice_3)> • For example, if the tutorial element requires a child called either name, title, or subject (but only one of these) <!ELEMENT tutorial (name | title | subject)>
  • 31. DTD Operators with Sequences • Can apply any of the DTD operators to a sequence: • Syntax: <!ELEMENT element_name (child_element_name dtd_operator, child_element_name dtd_operator,...)> • Example: <!ELEMENT tutorial (name+, author?)>
  • 32. DTD Attributes • Just as we need to define all elements in your DTD, we also need to define any attributes they use. • Use the <!ATTLIST> declaration to define attributes • Single <!ATTLIST> declaration to declare all attributes for a given element