際際滷

際際滷Share a Scribd company logo
Document Type Definitions
DTD
Contents
DTD Introduction
DTD Building Blocks
DTD Elements
DTD Attributes
DTD Elements vs Attributes
DTD Entities
DTD Summary
What is a DTD
 Defines the structure of an XML document
 Only the elements defined in a DTD can be used in
an XML document
 can be internal or external
 A DTD defines the structure of a valid XML
document
 Processing overhead is incurred when validating XML
with a DTD
Why Use a DTD?
 With a DTD, each of your XML files can carry a
description of its own format.
 With a DTD, independent groups of people can agree
to use a standard DTD for interchanging data.
 Your application can use a standard DTD to verify
that the data you receive from the outside world is
valid.
 You can also use a DTD to verify your own data.
Cont..
 XML documents are designed to be processed
by computer programs
 If you can put just any tags in an XML
document, its very hard to write a program
that knows how to process the tags.
 A DTD specifies what tags may occur, when
they may occur, and what attributes they
may (or must) have.
DTD Declaration
 A DTD can be declared inline inside an XML
document, or as an external reference.
Internal DTD Declaration
 If the DTD is declared inside the XML file, it
should be wrapped in a DOCTYPE definition
with the following syntax:
<!DOCTYPE root-element [element-declarations]>
Example: XML document with an 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>
The DTD above is interpreted like this:
 !DOCTYPE note defines that the root element of
this document is note
 !ELEMENT note defines that the note element
contains four elements: "to,from,heading,body"
 !ELEMENT to defines the to element to be of
type "#PCDATA"
 !ELEMENT from defines the from element to be
of type "#PCDATA"
 !ELEMENT heading defines the heading element
to be of type "#PCDATA"
 !ELEMENT body defines the body element to be
of type "#PCDATA"
External DTD Declaration
 If the DTD is declared in an external file, it
should be wrapped in a DOCTYPE definition
with the following syntax:
<!DOCTYPE root-element SYSTEM "filename">
<?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
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
And this is the file "note.dtd" which contains the DTD:
DTD- XML building blocks
The building blocks of XML documents
 Seen from a DTD point of view, all XML
documents (and HTML documents) are
made up by the following building blocks:
 Elements
 Attributes
 Entities
 PCDATA
 CDATA
]
Elements
 Elements are the main building blocks of both
XML and HTML documents.
 Examples of HTML elements are "body" and
"table".
 Examples of XML elements could be "note" and
"message". Elements can contain text, other
elements, or be empty. Examples of empty
HTML elements are "hr", "br" and "img".
 Examples:
<body>some text</body>
<message>some text</message>
Attributes
 Attributes provide extra information about
elements.
 Attributes are always placed inside the opening tag
of an element.
 Attributes always come in name/value pairs. The
following "img" element has additional information
about a source file:
 The name of the element is "img". The name of the
attribute is "src". The value of the attribute is
/slideshow/2dtdppt/251643658/"computer.gif". Since the element itself is empty it is
closed by a " /".
<img src=/slideshow/2dtdppt/251643658/"computer.gif" />
Attribute Rules
 attribute values must be placed in  
 in HTML this is only required id the attribute
contains the space character
 attribute values are not processed by the XML
parser
 this means the values cant be automatically
checked by the parser
Entities
 Some characters have a special meaning in
XML, like the less than sign (<) that defines the
start of an XML tag.
 Most of you know the HTML entity: "&nbsp;".
This "no-breaking-space" entity is used in
HTML to insert an extra space in a document.
 Entities are expanded when a document is
parsed by an XML parser.
Entities
Entity References Character
&lt; <
&gt; >
&amp; &
&quot; "
&apos; '
PCDATA
 PCDATA means parsed character data.
 Think of character data as the text found
between the start tag and the end tag of an
XML element.
 PCDATA is text that WILL be parsed by a
parser. The text will be examined by the parser
for entities and markup.
PCDATA
 Tags inside the text will be treated as markup
and entities will be expanded.
 However, parsed character data should not
contain any &, <, or > characters; these need
to be represented by the &amp; &lt; and &gt;
entities, respectively.
Cont
CDATA
 CDATA means character data.
 CDATA is text that will NOT be parsed by a
parser.
 Tags inside the text will NOT be treated as
markup and entities will not be expanded.
DTD - Elements
1.Declaring an Element
2.Empty Elements
3.Elements with Parsed Character Data
4.Elements with any Contents
5.Elements with Children (sequences)
6.Declaring Only One Occurrence of an Element
7.Declaring Minimum One Occurrence of an Element
8.Declaring Zero or More Occurrences of an Element
9.Declaring Zero or One Occurrences of an Element
10.Declaring either/or Content
11.Declaring Mixed Content
DTD - Elements
1. Declaring Elements:
 In a DTD, XML elements are declared with an
element declaration with the following syntax:
<!ELEMENT element-name category>
or
<!ELEMENT element-name (element-content)>
2. Empty Elements
 Empty elements are declared with the category
keyword EMPTY:
<!ELEMENT element-name EMPTY>
Example:
<!ELEMENT br EMPTY>
XML example:
<br />
3. Elements with Data
 Elements with data are declared with the data
type inside parentheses:
<!ELEMENT element-name (#CDATA)>
Or
<!ELEMENT element-name (#PCDATA)>
Example:
<!ELEMENT note (#PCDATA)>
4. Elements with any Contents
 Elements declared with the category keyword
ANY, can contain any combination of parsable
data:
<!ELEMENT element-name ANY>
Example:
<!ELEMENT note ANY>
5. Elements with Children (sequences)
 Elements with one or more children are declared
with the name of the children elements inside
parentheses:
<!ELEMENT element-name (child1)>
or
<!ELEMENT element-name (child1,child2,...)>
Example:
<!ELEMENT note (to,from,heading,body)>
 When children are declared in a sequence
separated by commas, the children must appear
in the same sequence in the document.
 In a full declaration, the children must also be
declared, and the children can also have children.
The full declaration of the "note" element is:
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
6. Declaring Only One Occurrence of an
Element
 <!ELEMENT element-name (child-name)>
 The example above declares that the child
element "message" must occur once, and
only once inside the "note" element.
Example:
<!ELEMENT note (message)>
7. Declaring Minimum One Occurrence of an
Element
 <!ELEMENT element-name (child-name+)>
 The + sign in the example above declares that
the child element "message" must occur one or
more times inside the "note" element.
Example:
<!ELEMENT note (message+)>
8. Declaring Zero or More Occurrences of an
Element
 The * sign in the example above declares that
the child element "message" can occur zero or
more times inside the "note" element.
<!ELEMENT element-name (child-name*)>
Example:
<!ELEMENT note (message*)>
9. Declaring Zero or One Occurrences of an
Element
 The ? sign in the example above declares that
the child element "message" can occur zero or
one time inside the "note" element.
<!ELEMENT element-name (child-name?)>
Example:
<!ELEMENT note (message?)>
10. Declaring either/or Content
 The example above declares that the "note"
element must contain a "to" element, a "from"
element, a "header" element, and either a
"message" or a "body" element.
Example:
<!ELEMENT note (to,from,header,(message|body))>
11. Declaring Mixed Content
 The example above declares that the "note"
element can contain zero or more occurrences
of parsed character data, "to", "from", "header",
or "message" elements.
Example:
<!ELEMENT note (#PCDATA|to|from|header|message)*>
DTD - Attributes
 In a DTD, attributes are declared with an
ATTLIST declaration.
Declaring Attributes
An attribute declaration has the following syntax:
Declaring Attributes
An attribute declaration has the following
syntax:
<!ATTLIST element-name attribute-name attribute-type default-value>
DTD example:
<!ATTLIST payment type CDATA "check">
XML example:
<payment type="check" />
Type Description
CDATA The value is Character data
(en1|en2|..) The value must be one from an enumerated
list
ID The value is a unique id
IDREF The value is the id of another element
IDREFS The value is a list of other ids
NMTOKEN The value is a valid XML name
NMTOKENS The value is a list of valid XML names
ENTITY The value is an entity
ENTITIES The value is a list of entities
NOTATION The value is a name of a notation
xml: The value is a predefined xml value
 The default-value can be one of the following:
Value Explanation
 value The default value of the attribute
 #REQUIRED The attribute is required
 #IMPLIED The attribute is not required
 #FIXED value The attribute value is fixed
A Default Attribute Value
 In the example above, the "square" element is
defined to be an empty element with a "width"
attribute of type CDATA.
 If no width is specified, it has a default value of 0.
DTD:
<!ELEMENT square EMPTY>
<!ATTLIST square width CDATA "0">
Valid XML:
<square width="100" />
#REQUIRED
<!ATTLIST element-name attribute-name attribute-type
#REQUIRED>
Example
DTD:
<!ATTLIST person number CDATA #REQUIRED>
Valid XML:
<person number="5677" />
Invalid XML:
<person />
Syntax
#REQUIRED
 Use the #REQUIRED keyword if you don't have
an option for a default value, but still want to
force the attribute to be present.
Cont..
#IMPLIED
 Use the #IMPLIED keyword if you don't want to force the
author to include an attribute, and you don't have an
option for a default value.
Syntax
<!ATTLIST element-name attribute-name attribute-type #IMPLIED>
Example
DTD:
<!ATTLIST contact fax CDATA #IMPLIED>
Valid XML:
<contact fax="555-667788" />
Valid XML:
<contact />
#FIXED
Syntax
<!ATTLIST element-name attribute-name
attribute-type #FIXED "value">
Example
DTD:
<!ATTLIST sender company CDATA #FIXED "Microsoft">
Valid XML:
<sender company="Microsoft" />
Invalid XML:
<sender company="W3Schools" />
Use the #FIXED keyword when you want an attribute to have a fixed
value without allowing the author to change it. If an author includes
another value, the XML parser will return an error
Enumerated Attribute Values
Syntax
<!ATTLIST element-name attribute-name (en1|en2|..)
default-value>
Example
DTD:
<!ATTLIST payment type (check|cash) "cash">
XML example:
<payment type="check" />
or
<payment type="cash" />
Use enumerated attribute values when you want the attribute
value to be one of a fixed set of legal values
Use of Elements vs. Attributes
 The following three XML documents contain
exactly the same information:
 A date attribute is used in the first example:
<note date="12/11/2002">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
 A date element is used in the second example:
<note>
<date>12/11/2002</date>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
 An expanded date element is used in the third:
<note>
<date>
<day>12</day>
<month>11</month>
<year>2002</year>
</date>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note
DTD - Entities
 Entities are variables used to define shortcuts to
standard text or special characters.
 Entity references are references to entities
 Entities can be declared internal or external
An Internal Entity Declaration
Syntax
<!ENTITY entity-name "entity-value"> Example
DTD Example:
<!ENTITY writer "Donald Duck.">
<!ENTITY copyright "Copyright W3Schools.">
XML example:
<author>&writer;&copyright;</author>
Note: An entity has three parts: an ampersand (&), an entity
name, and a semicolon (;).
An External Entity Declaration
Syntax
<!ENTITY entity-name SYSTEM "URI/URL">
Example
DTD Example:
<!ENTITY writer SYSTEM "http://www.w3schools.com/entities.dtd">
<!ENTITY copyright SYSTEM "http://www.w3schools.com/entities.dtd">
XML example:
<author>&writer;&copyright;</author>
DTD Summary
 You have learned how to use a DTD to define
the legal elements of an XML document, and
how a DTD can be declared inside your XML
document, or as an external reference.
 You have learned how to declare the legal
elements, attributes, entities, and CDATA
sections for XML documents.

More Related Content

Similar to 2-DTD.ppt (20)

XML DTD DOCUMENT TYPE DEFINITION
XML DTD DOCUMENT TYPE DEFINITIONXML DTD DOCUMENT TYPE DEFINITION
XML DTD DOCUMENT TYPE DEFINITION
SaraswathiRamalingam
Xml2
Xml2Xml2
Xml2
Abhishek Kesharwani
Document type definitions part 1
Document type definitions part 1Document type definitions part 1
Document type definitions part 1
Randy Riness @ South Puget Sound Community College
DTD
DTDDTD
DTD
Kumar
XML's validation - DTD
XML's validation - DTDXML's validation - DTD
XML's validation - DTD
videde_group
II UNIT PPT NOTES.pdf this is the data structures
II UNIT PPT NOTES.pdf this is the data structuresII UNIT PPT NOTES.pdf this is the data structures
II UNIT PPT NOTES.pdf this is the data structures
PriyankaRamavath3
DTD
DTDDTD
DTD
Kamal Acharya
Document Type Definition
Document Type DefinitionDocument Type Definition
Document Type Definition
yht4ever
Web Technologies Unit 2 Print.pdf
Web Technologies Unit 2 Print.pdfWeb Technologies Unit 2 Print.pdf
Web Technologies Unit 2 Print.pdf
AnonymousXhmybK
Chen test paper20abcdeftfdfd
Chen test paper20abcdeftfdfdChen test paper20abcdeftfdfd
Chen test paper20abcdeftfdfd
techweb08
Test for an issue
Test for an issueTest for an issue
Test for an issue
techweb08
Chen's first test slides
Chen's first test slidesChen's first test slides
Chen's first test slides
Hima Challa
XXE
XXEXXE
XXE
n|u - The Open Security Community
Xxe
XxeXxe
Xxe
nullowaspmumbai
01 xml document structure
01 xml document structure01 xml document structure
01 xml document structure
Baskarkncet
uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2
Abhishek Kesharwani
Xml and DTD's
Xml and DTD'sXml and DTD's
Xml and DTD's
Swati Parmar
Xml dtd
Xml dtdXml dtd
Xml dtd
HeenaRajput1
Unit 5 xml (1)
Unit 5   xml (1)Unit 5   xml (1)
Unit 5 xml (1)
manochitra10
Session 2
Session 2Session 2
Session 2
L畉i 畛c Chung

More from KGSCSEPSGCT (12)

Introduction to Distributed Systems
Introduction to Distributed SystemsIntroduction to Distributed Systems
Introduction to Distributed Systems
KGSCSEPSGCT
Unit4_Managing Contracts.ppt
Unit4_Managing Contracts.pptUnit4_Managing Contracts.ppt
Unit4_Managing Contracts.ppt
KGSCSEPSGCT
WSstandards.ppt
WSstandards.pptWSstandards.ppt
WSstandards.ppt
KGSCSEPSGCT
UDDI.ppt
UDDI.pptUDDI.ppt
UDDI.ppt
KGSCSEPSGCT
ROA.ppt
ROA.pptROA.ppt
ROA.ppt
KGSCSEPSGCT
REST Introduction.ppt
REST Introduction.pptREST Introduction.ppt
REST Introduction.ppt
KGSCSEPSGCT
3-SchemaExamples.pdf
3-SchemaExamples.pdf3-SchemaExamples.pdf
3-SchemaExamples.pdf
KGSCSEPSGCT
Converting DTDs to XML Schemas.pdf
Converting DTDs to XML Schemas.pdfConverting DTDs to XML Schemas.pdf
Converting DTDs to XML Schemas.pdf
KGSCSEPSGCT
XSL- XSLT.pdf
XSL- XSLT.pdfXSL- XSLT.pdf
XSL- XSLT.pdf
KGSCSEPSGCT
XML-INTRODUCTION.pdf
XML-INTRODUCTION.pdfXML-INTRODUCTION.pdf
XML-INTRODUCTION.pdf
KGSCSEPSGCT
XSLT.ppt
XSLT.pptXSLT.ppt
XSLT.ppt
KGSCSEPSGCT
XML Schema.pdf
XML Schema.pdfXML Schema.pdf
XML Schema.pdf
KGSCSEPSGCT
Introduction to Distributed Systems
Introduction to Distributed SystemsIntroduction to Distributed Systems
Introduction to Distributed Systems
KGSCSEPSGCT
Unit4_Managing Contracts.ppt
Unit4_Managing Contracts.pptUnit4_Managing Contracts.ppt
Unit4_Managing Contracts.ppt
KGSCSEPSGCT
WSstandards.ppt
WSstandards.pptWSstandards.ppt
WSstandards.ppt
KGSCSEPSGCT
REST Introduction.ppt
REST Introduction.pptREST Introduction.ppt
REST Introduction.ppt
KGSCSEPSGCT
3-SchemaExamples.pdf
3-SchemaExamples.pdf3-SchemaExamples.pdf
3-SchemaExamples.pdf
KGSCSEPSGCT
Converting DTDs to XML Schemas.pdf
Converting DTDs to XML Schemas.pdfConverting DTDs to XML Schemas.pdf
Converting DTDs to XML Schemas.pdf
KGSCSEPSGCT
XSL- XSLT.pdf
XSL- XSLT.pdfXSL- XSLT.pdf
XSL- XSLT.pdf
KGSCSEPSGCT
XML-INTRODUCTION.pdf
XML-INTRODUCTION.pdfXML-INTRODUCTION.pdf
XML-INTRODUCTION.pdf
KGSCSEPSGCT
XML Schema.pdf
XML Schema.pdfXML Schema.pdf
XML Schema.pdf
KGSCSEPSGCT

Recently uploaded (20)

Env and Water Supply Engg._Dr. Hasan.pdf
Env and Water Supply Engg._Dr. Hasan.pdfEnv and Water Supply Engg._Dr. Hasan.pdf
Env and Water Supply Engg._Dr. Hasan.pdf
MahmudHasan747870
Pioneers in planning theories Sir Ebenezer Howard
Pioneers in planning theories Sir Ebenezer HowardPioneers in planning theories Sir Ebenezer Howard
Pioneers in planning theories Sir Ebenezer Howard
JnaneshPreethan
INFORMATION AND COMMUNICATION TECHNOLOGY SKILLS' SUFFICIENCY OF EGYPTIAN ACCO...
INFORMATION AND COMMUNICATION TECHNOLOGY SKILLS' SUFFICIENCY OF EGYPTIAN ACCO...INFORMATION AND COMMUNICATION TECHNOLOGY SKILLS' SUFFICIENCY OF EGYPTIAN ACCO...
INFORMATION AND COMMUNICATION TECHNOLOGY SKILLS' SUFFICIENCY OF EGYPTIAN ACCO...
ijait
Water Industry Process Automation & Control Monthly - March 2025.pdf
Water Industry Process Automation & Control Monthly - March 2025.pdfWater Industry Process Automation & Control Monthly - March 2025.pdf
Water Industry Process Automation & Control Monthly - March 2025.pdf
Water Industry Process Automation & Control
Operations Management - Facility Location.pptx
Operations Management - Facility Location.pptxOperations Management - Facility Location.pptx
Operations Management - Facility Location.pptx
VirajPasare
Integration of Additive Manufacturing (AM) with IoT : A Smart Manufacturing A...
Integration of Additive Manufacturing (AM) with IoT : A Smart Manufacturing A...Integration of Additive Manufacturing (AM) with IoT : A Smart Manufacturing A...
Integration of Additive Manufacturing (AM) with IoT : A Smart Manufacturing A...
ASHISHDESAI85
Building a Strong Portfolio for Your Software Engineering Career
Building a Strong Portfolio for Your Software Engineering CareerBuilding a Strong Portfolio for Your Software Engineering Career
Building a Strong Portfolio for Your Software Engineering Career
Navinda Dissanayake
Lecture -3 Cold water supply system.pptx
Lecture -3 Cold water supply system.pptxLecture -3 Cold water supply system.pptx
Lecture -3 Cold water supply system.pptx
rabiaatif2
AI, Tariffs and Supply Chains in Knowledge Graphs
AI, Tariffs and Supply Chains in Knowledge GraphsAI, Tariffs and Supply Chains in Knowledge Graphs
AI, Tariffs and Supply Chains in Knowledge Graphs
Max De Marzi
Piping-and-pipeline-calculations-manual.pdf
Piping-and-pipeline-calculations-manual.pdfPiping-and-pipeline-calculations-manual.pdf
Piping-and-pipeline-calculations-manual.pdf
OMI0721
Table Creation in HTML using <table> tag
Table Creation in HTML using  <table> tagTable Creation in HTML using  <table> tag
Table Creation in HTML using <table> tag
pravin patil
Indian Knowledge System Veda and Vedangas .pptx
Indian Knowledge System Veda and Vedangas .pptxIndian Knowledge System Veda and Vedangas .pptx
Indian Knowledge System Veda and Vedangas .pptx
surekha1287
nptel 1, introduction to iot, By Prof. Sudip Misra
nptel 1, introduction to iot, By Prof. Sudip Misranptel 1, introduction to iot, By Prof. Sudip Misra
nptel 1, introduction to iot, By Prof. Sudip Misra
ayushmanyadavug22
David Boutry - A Senior Software Engineer
David Boutry - A Senior Software EngineerDavid Boutry - A Senior Software Engineer
David Boutry - A Senior Software Engineer
David Boutry
Royal Aeronautical Society - Certificate
Royal Aeronautical Society - CertificateRoyal Aeronautical Society - Certificate
Royal Aeronautical Society - Certificate
Javier Uriel G坦mez
Resource Cluster and Multi-Device Broker.pdf
Resource Cluster and Multi-Device Broker.pdfResource Cluster and Multi-Device Broker.pdf
Resource Cluster and Multi-Device Broker.pdf
Hitesh Mohapatra
Structural QA/QC Inspection in KRP 401600 | Copper Processing Plant-3 (MOF-3)...
Structural QA/QC Inspection in KRP 401600 | Copper Processing Plant-3 (MOF-3)...Structural QA/QC Inspection in KRP 401600 | Copper Processing Plant-3 (MOF-3)...
Structural QA/QC Inspection in KRP 401600 | Copper Processing Plant-3 (MOF-3)...
slayshadow705
Unit II: Design of Static Equipment Foundations
Unit II: Design of Static Equipment FoundationsUnit II: Design of Static Equipment Foundations
Unit II: Design of Static Equipment Foundations
Sanjivani College of Engineering, Kopargaon
Preliminary Evaluation of Inspection Assistance Methods Using VR Simulating P...
Preliminary Evaluation of Inspection Assistance Methods Using VR Simulating P...Preliminary Evaluation of Inspection Assistance Methods Using VR Simulating P...
Preliminary Evaluation of Inspection Assistance Methods Using VR Simulating P...
Kurata Takeshi
Lessons learned when managing MySQL in the Cloud
Lessons learned when managing MySQL in the CloudLessons learned when managing MySQL in the Cloud
Lessons learned when managing MySQL in the Cloud
Igor Donchovski
Env and Water Supply Engg._Dr. Hasan.pdf
Env and Water Supply Engg._Dr. Hasan.pdfEnv and Water Supply Engg._Dr. Hasan.pdf
Env and Water Supply Engg._Dr. Hasan.pdf
MahmudHasan747870
Pioneers in planning theories Sir Ebenezer Howard
Pioneers in planning theories Sir Ebenezer HowardPioneers in planning theories Sir Ebenezer Howard
Pioneers in planning theories Sir Ebenezer Howard
JnaneshPreethan
INFORMATION AND COMMUNICATION TECHNOLOGY SKILLS' SUFFICIENCY OF EGYPTIAN ACCO...
INFORMATION AND COMMUNICATION TECHNOLOGY SKILLS' SUFFICIENCY OF EGYPTIAN ACCO...INFORMATION AND COMMUNICATION TECHNOLOGY SKILLS' SUFFICIENCY OF EGYPTIAN ACCO...
INFORMATION AND COMMUNICATION TECHNOLOGY SKILLS' SUFFICIENCY OF EGYPTIAN ACCO...
ijait
Operations Management - Facility Location.pptx
Operations Management - Facility Location.pptxOperations Management - Facility Location.pptx
Operations Management - Facility Location.pptx
VirajPasare
Integration of Additive Manufacturing (AM) with IoT : A Smart Manufacturing A...
Integration of Additive Manufacturing (AM) with IoT : A Smart Manufacturing A...Integration of Additive Manufacturing (AM) with IoT : A Smart Manufacturing A...
Integration of Additive Manufacturing (AM) with IoT : A Smart Manufacturing A...
ASHISHDESAI85
Building a Strong Portfolio for Your Software Engineering Career
Building a Strong Portfolio for Your Software Engineering CareerBuilding a Strong Portfolio for Your Software Engineering Career
Building a Strong Portfolio for Your Software Engineering Career
Navinda Dissanayake
Lecture -3 Cold water supply system.pptx
Lecture -3 Cold water supply system.pptxLecture -3 Cold water supply system.pptx
Lecture -3 Cold water supply system.pptx
rabiaatif2
AI, Tariffs and Supply Chains in Knowledge Graphs
AI, Tariffs and Supply Chains in Knowledge GraphsAI, Tariffs and Supply Chains in Knowledge Graphs
AI, Tariffs and Supply Chains in Knowledge Graphs
Max De Marzi
Piping-and-pipeline-calculations-manual.pdf
Piping-and-pipeline-calculations-manual.pdfPiping-and-pipeline-calculations-manual.pdf
Piping-and-pipeline-calculations-manual.pdf
OMI0721
Table Creation in HTML using <table> tag
Table Creation in HTML using  <table> tagTable Creation in HTML using  <table> tag
Table Creation in HTML using <table> tag
pravin patil
Indian Knowledge System Veda and Vedangas .pptx
Indian Knowledge System Veda and Vedangas .pptxIndian Knowledge System Veda and Vedangas .pptx
Indian Knowledge System Veda and Vedangas .pptx
surekha1287
nptel 1, introduction to iot, By Prof. Sudip Misra
nptel 1, introduction to iot, By Prof. Sudip Misranptel 1, introduction to iot, By Prof. Sudip Misra
nptel 1, introduction to iot, By Prof. Sudip Misra
ayushmanyadavug22
David Boutry - A Senior Software Engineer
David Boutry - A Senior Software EngineerDavid Boutry - A Senior Software Engineer
David Boutry - A Senior Software Engineer
David Boutry
Royal Aeronautical Society - Certificate
Royal Aeronautical Society - CertificateRoyal Aeronautical Society - Certificate
Royal Aeronautical Society - Certificate
Javier Uriel G坦mez
Resource Cluster and Multi-Device Broker.pdf
Resource Cluster and Multi-Device Broker.pdfResource Cluster and Multi-Device Broker.pdf
Resource Cluster and Multi-Device Broker.pdf
Hitesh Mohapatra
Structural QA/QC Inspection in KRP 401600 | Copper Processing Plant-3 (MOF-3)...
Structural QA/QC Inspection in KRP 401600 | Copper Processing Plant-3 (MOF-3)...Structural QA/QC Inspection in KRP 401600 | Copper Processing Plant-3 (MOF-3)...
Structural QA/QC Inspection in KRP 401600 | Copper Processing Plant-3 (MOF-3)...
slayshadow705
Preliminary Evaluation of Inspection Assistance Methods Using VR Simulating P...
Preliminary Evaluation of Inspection Assistance Methods Using VR Simulating P...Preliminary Evaluation of Inspection Assistance Methods Using VR Simulating P...
Preliminary Evaluation of Inspection Assistance Methods Using VR Simulating P...
Kurata Takeshi
Lessons learned when managing MySQL in the Cloud
Lessons learned when managing MySQL in the CloudLessons learned when managing MySQL in the Cloud
Lessons learned when managing MySQL in the Cloud
Igor Donchovski

2-DTD.ppt

  • 2. Contents DTD Introduction DTD Building Blocks DTD Elements DTD Attributes DTD Elements vs Attributes DTD Entities DTD Summary
  • 3. What is a DTD Defines the structure of an XML document Only the elements defined in a DTD can be used in an XML document can be internal or external A DTD defines the structure of a valid XML document Processing overhead is incurred when validating XML with a DTD
  • 4. Why Use a DTD? With a DTD, each of your XML files can carry a description of its own format. With a DTD, independent groups of people can agree to use a standard DTD for interchanging data. Your application can use a standard DTD to verify that the data you receive from the outside world is valid. You can also use a DTD to verify your own data.
  • 5. Cont.. XML documents are designed to be processed by computer programs If you can put just any tags in an XML document, its very hard to write a program that knows how to process the tags. A DTD specifies what tags may occur, when they may occur, and what attributes they may (or must) have.
  • 6. DTD Declaration A DTD can be declared inline inside an XML document, or as an external reference. Internal DTD Declaration If the DTD is declared inside the XML file, it should be wrapped in a DOCTYPE definition with the following syntax: <!DOCTYPE root-element [element-declarations]>
  • 7. Example: XML document with an 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>
  • 8. The DTD above is interpreted like this: !DOCTYPE note defines that the root element of this document is note !ELEMENT note defines that the note element contains four elements: "to,from,heading,body" !ELEMENT to defines the to element to be of type "#PCDATA" !ELEMENT from defines the from element to be of type "#PCDATA" !ELEMENT heading defines the heading element to be of type "#PCDATA" !ELEMENT body defines the body element to be of type "#PCDATA"
  • 9. External DTD Declaration If the DTD is declared in an external file, it should be wrapped in a DOCTYPE definition with the following syntax: <!DOCTYPE root-element SYSTEM "filename">
  • 10. <?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 <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)> And this is the file "note.dtd" which contains the DTD:
  • 11. DTD- XML building blocks The building blocks of XML documents Seen from a DTD point of view, all XML documents (and HTML documents) are made up by the following building blocks: Elements Attributes Entities PCDATA CDATA
  • 12. ] Elements Elements are the main building blocks of both XML and HTML documents. Examples of HTML elements are "body" and "table". Examples of XML elements could be "note" and "message". Elements can contain text, other elements, or be empty. Examples of empty HTML elements are "hr", "br" and "img". Examples: <body>some text</body> <message>some text</message>
  • 13. Attributes Attributes provide extra information about elements. Attributes are always placed inside the opening tag of an element. Attributes always come in name/value pairs. The following "img" element has additional information about a source file: The name of the element is "img". The name of the attribute is "src". The value of the attribute is /slideshow/2dtdppt/251643658/"computer.gif". Since the element itself is empty it is closed by a " /". <img src=/slideshow/2dtdppt/251643658/"computer.gif" />
  • 14. Attribute Rules attribute values must be placed in in HTML this is only required id the attribute contains the space character attribute values are not processed by the XML parser this means the values cant be automatically checked by the parser
  • 15. Entities Some characters have a special meaning in XML, like the less than sign (<) that defines the start of an XML tag. Most of you know the HTML entity: "&nbsp;". This "no-breaking-space" entity is used in HTML to insert an extra space in a document. Entities are expanded when a document is parsed by an XML parser.
  • 16. Entities Entity References Character &lt; < &gt; > &amp; & &quot; " &apos; '
  • 17. PCDATA PCDATA means parsed character data. Think of character data as the text found between the start tag and the end tag of an XML element. PCDATA is text that WILL be parsed by a parser. The text will be examined by the parser for entities and markup.
  • 18. PCDATA Tags inside the text will be treated as markup and entities will be expanded. However, parsed character data should not contain any &, <, or > characters; these need to be represented by the &amp; &lt; and &gt; entities, respectively. Cont
  • 19. CDATA CDATA means character data. CDATA is text that will NOT be parsed by a parser. Tags inside the text will NOT be treated as markup and entities will not be expanded.
  • 20. DTD - Elements 1.Declaring an Element 2.Empty Elements 3.Elements with Parsed Character Data 4.Elements with any Contents 5.Elements with Children (sequences) 6.Declaring Only One Occurrence of an Element 7.Declaring Minimum One Occurrence of an Element 8.Declaring Zero or More Occurrences of an Element 9.Declaring Zero or One Occurrences of an Element 10.Declaring either/or Content 11.Declaring Mixed Content
  • 21. DTD - Elements 1. Declaring Elements: In a DTD, XML elements are declared with an element declaration with the following syntax: <!ELEMENT element-name category> or <!ELEMENT element-name (element-content)>
  • 22. 2. Empty Elements Empty elements are declared with the category keyword EMPTY: <!ELEMENT element-name EMPTY> Example: <!ELEMENT br EMPTY> XML example: <br />
  • 23. 3. Elements with Data Elements with data are declared with the data type inside parentheses: <!ELEMENT element-name (#CDATA)> Or <!ELEMENT element-name (#PCDATA)> Example: <!ELEMENT note (#PCDATA)>
  • 24. 4. Elements with any Contents Elements declared with the category keyword ANY, can contain any combination of parsable data: <!ELEMENT element-name ANY> Example: <!ELEMENT note ANY>
  • 25. 5. Elements with Children (sequences) Elements with one or more children are declared with the name of the children elements inside parentheses: <!ELEMENT element-name (child1)> or <!ELEMENT element-name (child1,child2,...)> Example: <!ELEMENT note (to,from,heading,body)>
  • 26. When children are declared in a sequence separated by commas, the children must appear in the same sequence in the document. In a full declaration, the children must also be declared, and the children can also have children. The full declaration of the "note" element is: <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)>
  • 27. 6. Declaring Only One Occurrence of an Element <!ELEMENT element-name (child-name)> The example above declares that the child element "message" must occur once, and only once inside the "note" element. Example: <!ELEMENT note (message)>
  • 28. 7. Declaring Minimum One Occurrence of an Element <!ELEMENT element-name (child-name+)> The + sign in the example above declares that the child element "message" must occur one or more times inside the "note" element. Example: <!ELEMENT note (message+)>
  • 29. 8. Declaring Zero or More Occurrences of an Element The * sign in the example above declares that the child element "message" can occur zero or more times inside the "note" element. <!ELEMENT element-name (child-name*)> Example: <!ELEMENT note (message*)>
  • 30. 9. Declaring Zero or One Occurrences of an Element The ? sign in the example above declares that the child element "message" can occur zero or one time inside the "note" element. <!ELEMENT element-name (child-name?)> Example: <!ELEMENT note (message?)>
  • 31. 10. Declaring either/or Content The example above declares that the "note" element must contain a "to" element, a "from" element, a "header" element, and either a "message" or a "body" element. Example: <!ELEMENT note (to,from,header,(message|body))>
  • 32. 11. Declaring Mixed Content The example above declares that the "note" element can contain zero or more occurrences of parsed character data, "to", "from", "header", or "message" elements. Example: <!ELEMENT note (#PCDATA|to|from|header|message)*>
  • 33. DTD - Attributes In a DTD, attributes are declared with an ATTLIST declaration.
  • 34. Declaring Attributes An attribute declaration has the following syntax: Declaring Attributes An attribute declaration has the following syntax: <!ATTLIST element-name attribute-name attribute-type default-value> DTD example: <!ATTLIST payment type CDATA "check"> XML example: <payment type="check" />
  • 35. Type Description CDATA The value is Character data (en1|en2|..) The value must be one from an enumerated list ID The value is a unique id IDREF The value is the id of another element IDREFS The value is a list of other ids NMTOKEN The value is a valid XML name NMTOKENS The value is a list of valid XML names ENTITY The value is an entity ENTITIES The value is a list of entities NOTATION The value is a name of a notation xml: The value is a predefined xml value
  • 36. The default-value can be one of the following: Value Explanation value The default value of the attribute #REQUIRED The attribute is required #IMPLIED The attribute is not required #FIXED value The attribute value is fixed
  • 37. A Default Attribute Value In the example above, the "square" element is defined to be an empty element with a "width" attribute of type CDATA. If no width is specified, it has a default value of 0. DTD: <!ELEMENT square EMPTY> <!ATTLIST square width CDATA "0"> Valid XML: <square width="100" />
  • 38. #REQUIRED <!ATTLIST element-name attribute-name attribute-type #REQUIRED> Example DTD: <!ATTLIST person number CDATA #REQUIRED> Valid XML: <person number="5677" /> Invalid XML: <person /> Syntax
  • 39. #REQUIRED Use the #REQUIRED keyword if you don't have an option for a default value, but still want to force the attribute to be present. Cont..
  • 40. #IMPLIED Use the #IMPLIED keyword if you don't want to force the author to include an attribute, and you don't have an option for a default value. Syntax <!ATTLIST element-name attribute-name attribute-type #IMPLIED> Example DTD: <!ATTLIST contact fax CDATA #IMPLIED> Valid XML: <contact fax="555-667788" /> Valid XML: <contact />
  • 41. #FIXED Syntax <!ATTLIST element-name attribute-name attribute-type #FIXED "value"> Example DTD: <!ATTLIST sender company CDATA #FIXED "Microsoft"> Valid XML: <sender company="Microsoft" /> Invalid XML: <sender company="W3Schools" /> Use the #FIXED keyword when you want an attribute to have a fixed value without allowing the author to change it. If an author includes another value, the XML parser will return an error
  • 42. Enumerated Attribute Values Syntax <!ATTLIST element-name attribute-name (en1|en2|..) default-value> Example DTD: <!ATTLIST payment type (check|cash) "cash"> XML example: <payment type="check" /> or <payment type="cash" /> Use enumerated attribute values when you want the attribute value to be one of a fixed set of legal values
  • 43. Use of Elements vs. Attributes The following three XML documents contain exactly the same information: A date attribute is used in the first example: <note date="12/11/2002"> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
  • 44. A date element is used in the second example: <note> <date>12/11/2002</date> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
  • 45. An expanded date element is used in the third: <note> <date> <day>12</day> <month>11</month> <year>2002</year> </date> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note
  • 46. DTD - Entities Entities are variables used to define shortcuts to standard text or special characters. Entity references are references to entities Entities can be declared internal or external
  • 47. An Internal Entity Declaration Syntax <!ENTITY entity-name "entity-value"> Example DTD Example: <!ENTITY writer "Donald Duck."> <!ENTITY copyright "Copyright W3Schools."> XML example: <author>&writer;&copyright;</author> Note: An entity has three parts: an ampersand (&), an entity name, and a semicolon (;).
  • 48. An External Entity Declaration Syntax <!ENTITY entity-name SYSTEM "URI/URL"> Example DTD Example: <!ENTITY writer SYSTEM "http://www.w3schools.com/entities.dtd"> <!ENTITY copyright SYSTEM "http://www.w3schools.com/entities.dtd"> XML example: <author>&writer;&copyright;</author>
  • 49. DTD Summary You have learned how to use a DTD to define the legal elements of an XML document, and how a DTD can be declared inside your XML document, or as an external reference. You have learned how to declare the legal elements, attributes, entities, and CDATA sections for XML documents.