SlideShare a Scribd company logo
XML DTD
1
Introduction to DTD
 A Document Type Definition (DTD) defines the legal
building blocks of an XML document. It defines the
document structure with a list of legal elements and
attributes.
 A DTD can be declared inline inside an XML document, or
as an external reference.
2
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.
3
DTD - XML Building Blocks
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 thatWILL be parsed by a parser. The
text will be examined by the parser for entities and
markup.
 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.4
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.
5
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)>
6
Empty Elements
 Empty elements are declared with the category keyword
EMPTY:
 <!ELEMENT element-name EMPTY>
Example:
<!ELEMENT br EMPTY>
XML example:
<br />
7
Elements with Parsed Character
Data
 Elements with only parsed character data are declared with
#PCDATA inside parentheses:
 <!ELEMENT element-name (#PCDATA)>
Example:
<!ELEMENT from (#PCDATA)>
8
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>
9
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)>
10
Declaring Only One Occurrence of
an Element
 <!ELEMENT element-name (child-name)>
Example:
<!ELEMENT note (message)>
11
Declaring Minimum One
Occurrence of an Element
 <!ELEMENT element-name (child-name+)>
Example:
<!ELEMENT note (message+)>
12
Declaring Zero or More
Occurrences of an Element
 <!ELEMENT element-name (child-name*)>
Example:
<!ELEMENT note (message*)>
13
Declaring either/or Content
 Example:
<!ELEMENT note (to,from,header,(message|body))>
 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
14
TYPES of DTD
Internal DTD
External DTD
15
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)>
]>
16
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend</body>
</note>
17
 !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"
18
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>
19
 And this is the file "note.dtd" which contains the DTD:
 <!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
20

More Related Content

What's hot (20)

XML's validation - DTD
XML's validation - DTDXML's validation - DTD
XML's validation - DTD
 
2 dtd - validating xml documents
2   dtd - validating xml documents2   dtd - validating xml documents
2 dtd - validating xml documents
 
Document type definition
Document type definitionDocument type definition
Document type definition
 
DTD
DTDDTD
DTD
 
Xml2
Xml2Xml2
Xml2
 
Xml dtd
Xml dtdXml dtd
Xml dtd
 
Document Type Definitions
Document Type DefinitionsDocument Type Definitions
Document Type Definitions
 
Jungahan web presentation
Jungahan web presentationJungahan web presentation
Jungahan web presentation
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
SQL Server - Querying and Managing XML Data
SQL Server - Querying and Managing XML DataSQL Server - Querying and Managing XML Data
SQL Server - Querying and Managing XML Data
 
Xml Java
Xml JavaXml Java
Xml Java
 
Basic XML
Basic XMLBasic XML
Basic XML
 
XML and DTD
XML and DTDXML and DTD
XML and DTD
 
Dtd
DtdDtd
Dtd
 
Sgml
SgmlSgml
Sgml
 
Basic xml syntax
Basic xml syntaxBasic xml syntax
Basic xml syntax
 
Intro to xml
Intro to xmlIntro to xml
Intro to xml
 
Document type definitions part 1
Document type definitions part 1Document type definitions part 1
Document type definitions part 1
 
01 xml document structure
01 xml document structure01 xml document structure
01 xml document structure
 
Xml
XmlXml
Xml
 

Viewers also liked

Mobile Voter PRO info sheet
Mobile Voter PRO info sheetMobile Voter PRO info sheet
Mobile Voter PRO info sheet
Melinda Gipson
 
Hospitality Marketing
Hospitality MarketingHospitality Marketing
Hospitality Marketing
Paula Stenzel
 
On Data Quality Assurance and Conflation Entanglement in Crowdsourcing for En...
On Data Quality Assurance and Conflation Entanglement in Crowdsourcing for En...On Data Quality Assurance and Conflation Entanglement in Crowdsourcing for En...
On Data Quality Assurance and Conflation Entanglement in Crowdsourcing for En...
Greenapps&web
 

Viewers also liked (17)

Mobile Voter PRO info sheet
Mobile Voter PRO info sheetMobile Voter PRO info sheet
Mobile Voter PRO info sheet
 
Slideshare1
Slideshare1 Slideshare1
Slideshare1
 
Avances tecnologicos 1ºg_mayra
Avances tecnologicos 1ºg_mayraAvances tecnologicos 1ºg_mayra
Avances tecnologicos 1ºg_mayra
 
Delphi study-improving-forest-and-land-governance
Delphi study-improving-forest-and-land-governanceDelphi study-improving-forest-and-land-governance
Delphi study-improving-forest-and-land-governance
 
Item #11 Howdy Parade
Item #11 Howdy ParadeItem #11 Howdy Parade
Item #11 Howdy Parade
 
043 notes
043   notes043   notes
043 notes
 
Hospitality Marketing
Hospitality MarketingHospitality Marketing
Hospitality Marketing
 
Easy edd phd talks 28 oct 2008
Easy edd phd talks 28 oct 2008Easy edd phd talks 28 oct 2008
Easy edd phd talks 28 oct 2008
 
Taxi vinasun 2016 unique
Taxi vinasun 2016   uniqueTaxi vinasun 2016   unique
Taxi vinasun 2016 unique
 
On Data Quality Assurance and Conflation Entanglement in Crowdsourcing for En...
On Data Quality Assurance and Conflation Entanglement in Crowdsourcing for En...On Data Quality Assurance and Conflation Entanglement in Crowdsourcing for En...
On Data Quality Assurance and Conflation Entanglement in Crowdsourcing for En...
 
Tutorial Picturetrail
Tutorial PicturetrailTutorial Picturetrail
Tutorial Picturetrail
 
Primend Pilvekonverents - Äri vajadused = IT eesmärgid
Primend Pilvekonverents - Äri vajadused = IT eesmärgid Primend Pilvekonverents - Äri vajadused = IT eesmärgid
Primend Pilvekonverents - Äri vajadused = IT eesmärgid
 
Grow your international software service firm
Grow your international software service firmGrow your international software service firm
Grow your international software service firm
 
uptu web technology unit 2 html
uptu web technology unit 2 htmluptu web technology unit 2 html
uptu web technology unit 2 html
 
E i FuL / RB
E i FuL / RBE i FuL / RB
E i FuL / RB
 
LAG-Report 2013
LAG-Report 2013LAG-Report 2013
LAG-Report 2013
 
Social Media Tools für Profis
Social Media Tools  für ProfisSocial Media Tools  für Profis
Social Media Tools für Profis
 

Similar to Xml2

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
 
Xml For Dummies Chapter 8 Understanding And Using Dt Ds it-slideshares.blog...
Xml For Dummies   Chapter 8 Understanding And Using Dt Ds it-slideshares.blog...Xml For Dummies   Chapter 8 Understanding And Using Dt Ds it-slideshares.blog...
Xml For Dummies Chapter 8 Understanding And Using Dt Ds it-slideshares.blog...
phanleson
 

Similar to Xml2 (20)

2-DTD.ppt
2-DTD.ppt2-DTD.ppt
2-DTD.ppt
 
It8074 soa-unit i
It8074 soa-unit iIt8074 soa-unit i
It8074 soa-unit i
 
it8074-soa-uniti-.pdf
it8074-soa-uniti-.pdfit8074-soa-uniti-.pdf
it8074-soa-uniti-.pdf
 
uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2
 
DTD1.pptx
DTD1.pptxDTD1.pptx
DTD1.pptx
 
Unit iv xml
Unit iv xmlUnit iv xml
Unit iv xml
 
XML DTD DOCUMENT TYPE DEFINITION
XML DTD DOCUMENT TYPE DEFINITIONXML DTD DOCUMENT TYPE DEFINITION
XML DTD DOCUMENT TYPE DEFINITION
 
XML Validations.ppt
XML Validations.pptXML Validations.ppt
XML Validations.ppt
 
distributed system concerned lab sessions
distributed system concerned lab sessionsdistributed system concerned lab sessions
distributed system concerned lab sessions
 
It8074 soa-unit i
It8074 soa-unit iIt8074 soa-unit i
It8074 soa-unit i
 
XXE
XXEXXE
XXE
 
Xxe
XxeXxe
Xxe
 
Chen test paper20abcdeftfdfd
Chen test paper20abcdeftfdfdChen test paper20abcdeftfdfd
Chen test paper20abcdeftfdfd
 
Test for an issue
Test for an issueTest for an issue
Test for an issue
 
Chen's first test slides
Chen's first test slidesChen's first test slides
Chen's first test slides
 
Encoded Archival Description (EAD)
Encoded Archival Description (EAD) Encoded Archival Description (EAD)
Encoded Archival Description (EAD)
 
Session 2
Session 2Session 2
Session 2
 
Xml sasidhar
Xml  sasidharXml  sasidhar
Xml sasidhar
 
Xml For Dummies Chapter 8 Understanding And Using Dt Ds it-slideshares.blog...
Xml For Dummies   Chapter 8 Understanding And Using Dt Ds it-slideshares.blog...Xml For Dummies   Chapter 8 Understanding And Using Dt Ds it-slideshares.blog...
Xml For Dummies Chapter 8 Understanding And Using Dt Ds it-slideshares.blog...
 
Xml
XmlXml
Xml
 

More from Abhishek Kesharwani

More from Abhishek Kesharwani (20)

uptu web technology unit 2 html
uptu web technology unit 2 htmluptu web technology unit 2 html
uptu web technology unit 2 html
 
uptu web technology unit 2 html
uptu web technology unit 2 htmluptu web technology unit 2 html
uptu web technology unit 2 html
 
uptu web technology unit 2 html
uptu web technology unit 2 htmluptu web technology unit 2 html
uptu web technology unit 2 html
 
uptu web technology unit 2 html
uptu web technology unit 2 htmluptu web technology unit 2 html
uptu web technology unit 2 html
 
uptu web technology unit 2 Css
uptu web technology unit 2 Cssuptu web technology unit 2 Css
uptu web technology unit 2 Css
 
uptu web technology unit 2 Css
uptu web technology unit 2 Cssuptu web technology unit 2 Css
uptu web technology unit 2 Css
 
uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2
 
uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2
 
uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2
 
Unit 1 web technology uptu slide
Unit 1 web technology uptu slideUnit 1 web technology uptu slide
Unit 1 web technology uptu slide
 
Unit1 Web Technology UPTU UNIT 1
Unit1 Web Technology UPTU UNIT 1 Unit1 Web Technology UPTU UNIT 1
Unit1 Web Technology UPTU UNIT 1
 
Unit1 2
Unit1 2 Unit1 2
Unit1 2
 
Web Technology UPTU UNIT 1
Web Technology UPTU UNIT 1 Web Technology UPTU UNIT 1
Web Technology UPTU UNIT 1
 
Mtech syllabus computer science uptu
Mtech syllabus computer science uptu Mtech syllabus computer science uptu
Mtech syllabus computer science uptu
 
Wi max tutorial
Wi max tutorialWi max tutorial
Wi max tutorial
 
Virtual lan
Virtual lanVirtual lan
Virtual lan
 
Virtual lan
Virtual lanVirtual lan
Virtual lan
 
Tcp traffic control and red ecn
Tcp traffic control and red ecnTcp traffic control and red ecn
Tcp traffic control and red ecn
 
Schedulling
SchedullingSchedulling
Schedulling
 
Scheduling
SchedulingScheduling
Scheduling
 

Xml2

  • 2. Introduction to DTD  A Document Type Definition (DTD) defines the legal building blocks of an XML document. It defines the document structure with a list of legal elements and attributes.  A DTD can be declared inline inside an XML document, or as an external reference. 2
  • 3. 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. 3
  • 4. DTD - XML Building Blocks 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 thatWILL be parsed by a parser. The text will be examined by the parser for entities and markup.  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.4
  • 5. 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. 5
  • 6. 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)> 6
  • 7. Empty Elements  Empty elements are declared with the category keyword EMPTY:  <!ELEMENT element-name EMPTY> Example: <!ELEMENT br EMPTY> XML example: <br /> 7
  • 8. Elements with Parsed Character Data  Elements with only parsed character data are declared with #PCDATA inside parentheses:  <!ELEMENT element-name (#PCDATA)> Example: <!ELEMENT from (#PCDATA)> 8
  • 9. 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> 9
  • 10. 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)> 10
  • 11. Declaring Only One Occurrence of an Element  <!ELEMENT element-name (child-name)> Example: <!ELEMENT note (message)> 11
  • 12. Declaring Minimum One Occurrence of an Element  <!ELEMENT element-name (child-name+)> Example: <!ELEMENT note (message+)> 12
  • 13. Declaring Zero or More Occurrences of an Element  <!ELEMENT element-name (child-name*)> Example: <!ELEMENT note (message*)> 13
  • 14. Declaring either/or Content  Example: <!ELEMENT note (to,from,header,(message|body))>  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 14
  • 15. TYPES of DTD Internal DTD External DTD 15
  • 16. 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)> ]> 16
  • 18.  !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" 18
  • 19. 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> 19
  • 20.  And this is the file "note.dtd" which contains the DTD:  <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)> 20