SlideShare a Scribd company logo
1 of 25
Download to read offline
7/9/2019
Prepared By: Dr.Saranya.K.G 1
Document Type Definitions
DTD
Prepared By: Dr.Saranya.K.G
Contents
DTD Introduction
DTD Building Blocks
DTD Elements
DTD Attributes
DTD Elements vs Attributes
DTD Entities
DTD Summary
Prepared By: Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 2
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
Prepared By: Dr.Saranya.K.G
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.
Prepared By: Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 3
Cont..
• XML documents are designed to be processed
by computer programs
– If you can put just any tags in an XML
document, it’s 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.
Prepared By: Dr.Saranya.K.G
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]>
Prepared By: Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 4
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>
Prepared By: Dr.Saranya.K.G
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"
Prepared By: Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 5
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">
Prepared By: Dr.Saranya.K.G
<?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:
Prepared By: Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 6
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
Prepared By: Dr.Saranya.K.G
]
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>
Prepared By: Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 7
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
"computer.gif". Since the element itself is empty it is
closed by a " /".
<img src="computer.gif" />
Prepared By: Dr.Saranya.K.G
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 can’t be automatically
checked by the parser
Prepared By: Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 8
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.
Prepared By: Dr.Saranya.K.G
Entities
Entity References Character
&lt; <
&gt; >
&amp; &
&quot; "
&apos; '
Prepared By: Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 9
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.
Prepared By: Dr.Saranya.K.G
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…
Prepared By: Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 10
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.
Prepared By: Dr.Saranya.K.G
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
Prepared By: Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 11
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)>
Prepared By: Dr.Saranya.K.G
2. Empty Elements
• Empty elements are declared with the category
keyword EMPTY:
<!ELEMENT element-name EMPTY>
Example:
<!ELEMENT br EMPTY>
XML example:
<br />
Prepared By: Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 12
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)>
Prepared By: Dr.Saranya.K.G
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>
Prepared By: Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 13
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)>
Prepared By: Dr.Saranya.K.G
• 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)>
Prepared By: Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 14
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)>
Prepared By: Dr.Saranya.K.G
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+)>
Prepared By: Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 15
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*)>
Prepared By: Dr.Saranya.K.G
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?)>
Prepared By: Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 16
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))>
Prepared By: Dr.Saranya.K.G
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)*>
Prepared By: Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 17
DTD - Attributes
• In a DTD, attributes are declared with an
ATTLIST declaration.
Prepared By: Dr.Saranya.K.G
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" />
Prepared By: Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 18
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
Prepared By: Dr.Saranya.K.G
• 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
Prepared By: Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 19
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" />
Prepared By: Dr.Saranya.K.G
#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
Prepared By: Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 20
#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..
Prepared By: Dr.Saranya.K.G
#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 />
Prepared By: Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 21
#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
Prepared By: Dr.Saranya.K.G
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
Prepared By: Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 22
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>
Prepared By: Dr.Saranya.K.G
• 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>
Prepared By: Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 23
• 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
Prepared By: Dr.Saranya.K.G
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
Prepared By: Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 24
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 (;).
Prepared By: Dr.Saranya.K.G
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>
Prepared By: Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 25
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.
Prepared By: Dr.Saranya.K.G

More Related Content

Similar to Dtd (20)

it8074-soa-uniti-.pdf
it8074-soa-uniti-.pdfit8074-soa-uniti-.pdf
it8074-soa-uniti-.pdf
 
It8074 soa-unit i
It8074 soa-unit iIt8074 soa-unit i
It8074 soa-unit i
 
Dtd
DtdDtd
Dtd
 
Xml2
Xml2Xml2
Xml2
 
Xml dtd
Xml dtdXml dtd
Xml dtd
 
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
 
Chen test paper20abcdeftfdfd
Chen test paper20abcdeftfdfdChen test paper20abcdeftfdfd
Chen test paper20abcdeftfdfd
 
Web Technologies Unit 2 Print.pdf
Web Technologies Unit 2 Print.pdfWeb Technologies Unit 2 Print.pdf
Web Technologies Unit 2 Print.pdf
 
Xml2
Xml2Xml2
Xml2
 
uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2
 
Session 2
Session 2Session 2
Session 2
 
XML DTD DOCUMENT TYPE DEFINITION
XML DTD DOCUMENT TYPE DEFINITIONXML DTD DOCUMENT TYPE DEFINITION
XML DTD DOCUMENT TYPE DEFINITION
 
Xml
XmlXml
Xml
 
Xml11
Xml11Xml11
Xml11
 
Xml Presentation-1
Xml Presentation-1Xml Presentation-1
Xml Presentation-1
 
Document Type Definition
Document Type DefinitionDocument Type Definition
Document Type Definition
 
Unit 5 xml (1)
Unit 5   xml (1)Unit 5   xml (1)
Unit 5 xml (1)
 
Xml
XmlXml
Xml
 
Xml part2
Xml part2Xml part2
Xml part2
 

More from Dr.Saranya K.G

More from Dr.Saranya K.G (12)

complete web service1.ppt
complete web service1.pptcomplete web service1.ppt
complete web service1.ppt
 
Introduction to Web Services Protocols.ppt
Introduction to Web Services Protocols.pptIntroduction to Web Services Protocols.ppt
Introduction to Web Services Protocols.ppt
 
1.Usability Engineering.pptx
1.Usability Engineering.pptx1.Usability Engineering.pptx
1.Usability Engineering.pptx
 
CSSE375-03-framework.ppt
CSSE375-03-framework.pptCSSE375-03-framework.ppt
CSSE375-03-framework.ppt
 
SQA.ppt
SQA.pptSQA.ppt
SQA.ppt
 
Neo4 j
Neo4 jNeo4 j
Neo4 j
 
Xquery1
Xquery1Xquery1
Xquery1
 
Xsl xslt
Xsl  xsltXsl  xslt
Xsl xslt
 
Xpath1
Xpath1Xpath1
Xpath1
 
Converting dt ds to xml schemas
Converting dt ds to xml schemasConverting dt ds to xml schemas
Converting dt ds to xml schemas
 
Xml schema
Xml schemaXml schema
Xml schema
 
1 xml fundamentals
1 xml fundamentals1 xml fundamentals
1 xml fundamentals
 

Recently uploaded

High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAbhinavSharma374939
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 

Recently uploaded (20)

High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog Converter
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 

Dtd

  • 1. 7/9/2019 Prepared By: Dr.Saranya.K.G 1 Document Type Definitions DTD Prepared By: Dr.Saranya.K.G Contents DTD Introduction DTD Building Blocks DTD Elements DTD Attributes DTD Elements vs Attributes DTD Entities DTD Summary Prepared By: Dr.Saranya.K.G
  • 2. 7/9/2019 Prepared By: Dr.Saranya.K.G 2 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 Prepared By: Dr.Saranya.K.G 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. Prepared By: Dr.Saranya.K.G
  • 3. 7/9/2019 Prepared By: Dr.Saranya.K.G 3 Cont.. • XML documents are designed to be processed by computer programs – If you can put just any tags in an XML document, it’s 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. Prepared By: Dr.Saranya.K.G 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]> Prepared By: Dr.Saranya.K.G
  • 4. 7/9/2019 Prepared By: Dr.Saranya.K.G 4 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> Prepared By: Dr.Saranya.K.G 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" Prepared By: Dr.Saranya.K.G
  • 5. 7/9/2019 Prepared By: Dr.Saranya.K.G 5 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"> Prepared By: Dr.Saranya.K.G <?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: Prepared By: Dr.Saranya.K.G
  • 6. 7/9/2019 Prepared By: Dr.Saranya.K.G 6 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 Prepared By: Dr.Saranya.K.G ] 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> Prepared By: Dr.Saranya.K.G
  • 7. 7/9/2019 Prepared By: Dr.Saranya.K.G 7 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 "computer.gif". Since the element itself is empty it is closed by a " /". <img src="computer.gif" /> Prepared By: Dr.Saranya.K.G 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 can’t be automatically checked by the parser Prepared By: Dr.Saranya.K.G
  • 8. 7/9/2019 Prepared By: Dr.Saranya.K.G 8 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. Prepared By: Dr.Saranya.K.G Entities Entity References Character &lt; < &gt; > &amp; & &quot; " &apos; ' Prepared By: Dr.Saranya.K.G
  • 9. 7/9/2019 Prepared By: Dr.Saranya.K.G 9 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. Prepared By: Dr.Saranya.K.G 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… Prepared By: Dr.Saranya.K.G
  • 10. 7/9/2019 Prepared By: Dr.Saranya.K.G 10 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. Prepared By: Dr.Saranya.K.G 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 Prepared By: Dr.Saranya.K.G
  • 11. 7/9/2019 Prepared By: Dr.Saranya.K.G 11 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)> Prepared By: Dr.Saranya.K.G 2. Empty Elements • Empty elements are declared with the category keyword EMPTY: <!ELEMENT element-name EMPTY> Example: <!ELEMENT br EMPTY> XML example: <br /> Prepared By: Dr.Saranya.K.G
  • 12. 7/9/2019 Prepared By: Dr.Saranya.K.G 12 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)> Prepared By: Dr.Saranya.K.G 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> Prepared By: Dr.Saranya.K.G
  • 13. 7/9/2019 Prepared By: Dr.Saranya.K.G 13 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)> Prepared By: Dr.Saranya.K.G • 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)> Prepared By: Dr.Saranya.K.G
  • 14. 7/9/2019 Prepared By: Dr.Saranya.K.G 14 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)> Prepared By: Dr.Saranya.K.G 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+)> Prepared By: Dr.Saranya.K.G
  • 15. 7/9/2019 Prepared By: Dr.Saranya.K.G 15 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*)> Prepared By: Dr.Saranya.K.G 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?)> Prepared By: Dr.Saranya.K.G
  • 16. 7/9/2019 Prepared By: Dr.Saranya.K.G 16 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))> Prepared By: Dr.Saranya.K.G 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)*> Prepared By: Dr.Saranya.K.G
  • 17. 7/9/2019 Prepared By: Dr.Saranya.K.G 17 DTD - Attributes • In a DTD, attributes are declared with an ATTLIST declaration. Prepared By: Dr.Saranya.K.G 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" /> Prepared By: Dr.Saranya.K.G
  • 18. 7/9/2019 Prepared By: Dr.Saranya.K.G 18 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 Prepared By: Dr.Saranya.K.G • 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 Prepared By: Dr.Saranya.K.G
  • 19. 7/9/2019 Prepared By: Dr.Saranya.K.G 19 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" /> Prepared By: Dr.Saranya.K.G #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 Prepared By: Dr.Saranya.K.G
  • 20. 7/9/2019 Prepared By: Dr.Saranya.K.G 20 #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.. Prepared By: Dr.Saranya.K.G #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 /> Prepared By: Dr.Saranya.K.G
  • 21. 7/9/2019 Prepared By: Dr.Saranya.K.G 21 #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 Prepared By: Dr.Saranya.K.G 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 Prepared By: Dr.Saranya.K.G
  • 22. 7/9/2019 Prepared By: Dr.Saranya.K.G 22 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> Prepared By: Dr.Saranya.K.G • 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> Prepared By: Dr.Saranya.K.G
  • 23. 7/9/2019 Prepared By: Dr.Saranya.K.G 23 • 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 Prepared By: Dr.Saranya.K.G 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 Prepared By: Dr.Saranya.K.G
  • 24. 7/9/2019 Prepared By: Dr.Saranya.K.G 24 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 (;). Prepared By: Dr.Saranya.K.G 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> Prepared By: Dr.Saranya.K.G
  • 25. 7/9/2019 Prepared By: Dr.Saranya.K.G 25 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. Prepared By: Dr.Saranya.K.G