SlideShare a Scribd company logo
Introduction to DTD
Kristian Torp
Department of Computer Science
Aalborg University
people.cs.aau.dk/˜torp
torp@cs.aau.dk
November 3, 2015
daisy.aau.dk
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 1 / 37
Outline
1 Introduction
2 Elements
3 Attributes
4 DTD Find Errors
5 Putting it All Together
6 Summary
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 2 / 37
Learning Outcomes
Learning Outcomes
Be able to read and understand a DTD
Be able to construct a DTD for a set of existing XML documents
Be able to validate an XML document against a DTD
Know the limitations of a DTD
Database Focus
All XML technologies are presented from a database perspective!
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 3 / 37
Outline
1 Introduction
2 Elements
3 Attributes
4 DTD Find Errors
5 Putting it All Together
6 Summary
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 4 / 37
Example: Course Catalog XML Document
User Requirements
Make a DTD for the course catalog
Use the DTD to validate our course catalog XML document
Example (Current Courses)
<?xml version=” 1.0 ” ?>
<coursecatalog>
<course cid= ’P4 ’>
<name>OOP</name>
<semester>3</ semester>
<desc>Object−oriented programming</ desc>
</ course>
<course cid= ’P2 ’>
<name>DB</name>
<semester>7</ semester>
<desc>Databases including SQL</ desc>
</ course>
</ coursecatalog>
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 5 / 37
Example: Course Catalog DTD
Example (DTD for Course Catalog)
<?xml version=” 1.0 ” encoding=”UTF−8” ?>
<!ELEMENT coursecatalog ( course )∗>
<!ELEMENT course (name, semester , desc ) >
<!ELEMENT name (#PCDATA)>
<!ELEMENT semester (#PCDATA)>
<!ELEMENT desc (#PCDATA)>
<! ATTLIST course cid ID #REQUIRED>
Informal Description
A course catalog consists of zero or more of courses
A course consists of a name, a semester, and a description
It is identified by an ID that is required
A (course) name is a string (leaf in XML document)
A semester is a string (leaf in XML document)
A description is a string (leaf in XML document)
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 6 / 37
Overview
Purpose
Define the document structure
Legal elements and attributes
Serves the same purpose as a create table statement in SQL
Structure and type of data
Integrity constraints!
Left over from SGML
Is not written in XML
If this is a requirement then use XML Schema
Still very widely used
Because much simpler than XML Schema
Note
Many simple errors can be found using a DTD
A necessity if receiving XML documents from external sources
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 7 / 37
Outline
1 Introduction
2 Elements
3 Attributes
4 DTD Find Errors
5 Putting it All Together
6 Summary
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 8 / 37
Simplest Entity
Example (Element Declaration)
<!ELEMENT name (#PCDATA)>
Example (Allowed Values)
<name>Hello Element</name>
<name/>
<name><![CDATA[ select ∗ from emp where sal > 10]]></name>
Example (Illegal Values)
<name>> </name>
<name>&gt;</name>
<name><it>Hello</it></name>
Unknown element <it>, must be defined in DTD
Note
Root, internal-node, and leafs in XML tree representation
Terminal and non-terminal in grammar terminology
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 9 / 37
Sequences of Child Elements
Example (Element Declaration)
<!ELEMENT course (name, semester, desc)>
Example (Allowed XML Fragment, Why?)
<course>
<name>OOP</name>
<semester>7</ semester>
<desc>I n t r o d u c t i o n to OOP</ desc>
</ course>
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 10 / 37
Sequences of Child Elements
Example (Element Declaration)
<!ELEMENT course (name, semester, desc)>
Example (Allowed XML Fragment, Why?)
<course>
<name>OOP</name>
<semester>7</ semester>
<desc>I n t r o d u c t i o n to OOP</ desc>
</ course>
Example (Disallowed XML Fragment, Why?)
<course>
<semester>7</ semester>
<name>OOP</name>
</ course>
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 10 / 37
Sequences of Child Elements
Example (Element Declaration)
<!ELEMENT course (name, semester, desc)>
Example (Allowed XML Fragment, Why?)
<course>
<name>OOP</name>
<semester>7</ semester>
<desc>I n t r o d u c t i o n to OOP</ desc>
</ course>
Example (Disallowed XML Fragment, Why?)
<course>
<semester>7</ semester>
<name>OOP</name>
</ course>
Example (Is this allowed?)
<course></ course>
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 10 / 37
Choice Among Child Elements
Example (Element Declaration)
<!ELEMENT circle (x, y, (radius | diameter))>
Example (Allowed XML Fragment)
< c i r c l e>
<x>5</ x>
<y>9</ y>
<diameter>7</ diameter>
</ c i r c l e>
Example (Illegal XML Fragment)
< c i r c l e>
<x>4</ x>
<y>8</ y>
<radius>3.5</ radius>
<diameter>7</ diameter>
</ c i r c l e>
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 11 / 37
Symbols in a DTD
Symbols
Symbol Example
∗ <!ELEMENT coursecatalog (course)∗>
+ <!ELEMENT coursecatalog (course)+>
? <!ELEMENT coursecatalog (course)?>
, <!ELEMENT course (name, semester, desc) >
| <!ELEMENT course (name | semester | desc) >
Note
Symbols are mostly taken from regular expressions
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 12 / 37
Mixed Content
Example (Data Centric)
<!ELEMENT coor ( x , y )>
Example (Allowed Fragment)
<coor>
<x>5</ x>
<y>9</ y>
</ coor>
Example (Mixed Content)
<!ELEMENT coor ( x , y , #PCDATA)∗>
Example (Allowed Fragment)
<coor>
This i s the coordinate
(<x>5</ x> , <y>9</ y>) where
the treasure i s hidden !
</ coor>
Note
Data centric very table like
Mixed content also called narrative document
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 13 / 37
Element Declarations using ANY
Example (Any)
<!ELEMENT coor (ANY)>
<!ELEMENT x (#PCDATA)
<!ELEMENT y (#PCDATA)
Example (Allowed Fragments)
<coor/>
<coor>Hello World</coor>
<coor>Hello <x>1</x><x/>World<y>3</y><y>4</y></coor>
<coor>Hello <x>1</x><y>2</y>World<y>3</y><x>4</x></coor>
Example (Illegal Fragments)
<coor><z>1</z></coor>
<coor><x>1</x><y>1<y/><z>1</z></coor>
Note
ANY handy for narrative documents, e.g., HTML
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 14 / 37
Element Declarations using EMPTY
Example (Empty)
<!ELEMENT coor EMPTY>
Example (Allowed?)
<coor></coor>
<coor/>
<coor>Hello</coor>
<coor><x>Hello</x></coor>
<coor> </coor>
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 15 / 37
Summary: Elements
Repetition
Symbol Explanation Example
? zero-or-one <!ELEMENT person (address?)>
* zero-or-more <!ELEMENT person (address∗)>
+ one-or-more <!ELEMENT person (address+)>
once <!ELEMENT person (address)>
Sequence or Choice
Symbol Explanation Example
, Sequence <!ELEMENT coor (x, y)>
| Choice <!ELEMENT coor (x | y)>
Data Type
Symbol Explanation Example
#PCDATA String <!ELEMENT name (#PCDATA)>
ANY What ever <!ELEMENT coor (ANY)>
EMPTY Empty <!ELEMENT room EMPTY>
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 16 / 37
Outline
1 Introduction
2 Elements
3 Attributes
4 DTD Find Errors
5 Putting it All Together
6 Summary
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 17 / 37
Attribute Declarations
Example (Circles)
<?xml version= ’ 1.0 ’ encoding= ’ utf −8 ’?>
<!ELEMENT drawing ( c i r c l e )∗>
<!ELEMENT c i r c l e ( x , y , ( radius | diameter ) )>
<! ATTLIST c i r c l e cid ID #REQUIRED
name CDATA #IMPLIED >
<!ELEMENT x (#PCDATA)>
<!ELEMENT y (#PCDATA)>
<!ELEMENT radius (#PCDATA)>
<! ATTLIST radius u n i t (mm|cm |m) ”m”> <!−− Enum with default −−>
<!ELEMENT diameter (#PCDATA)>
<! ATTLIST diameter u n i t (mm|cm |m) #REQUIRED> <!−− Enum no default −−>
Note
Mandatory and optional attributes
One or more attributes
Enumeration with defaults
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 18 / 37
Example Document
Example (Circles)
<?xml version=” 1.0 ” encoding= ’UTF−8 ’?>
<!DOCTYPE drawing SYSTEM ” c i r c l e a t t . dtd ”>
<drawing>
< c i r c l e cid= ’C1 ’ name= ’ f o r e s t ’>
<x>8</ x> <y>8</ y>
<radius>4</ radius> <!−− default u n i t−−>
</ c i r c l e>
< c i r c l e cid= ’C2 ’> <!−− name not required −−>
<x>5</ x> <y>5</ y>
<radius u n i t =”cm”>4</ radius> <!−− e x p l i c i t u n i t−−>
</ c i r c l e>
</ drawing>
Note
Unique value is not an integer
Used that attribute name is optional in element circle
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 19 / 37
Uniqueness, Examples
Example (Circle/Points with IDs)
<?xml version= ’ 1.0 ’ encoding= ’ utf −8 ’?>
<!ELEMENT drawing ( point | c i r c l e )∗>
<!ELEMENT point ( x , y )>
<!ELEMENT c i r c l e ( x , y , ( radius | diameter ) )>
<! ATTLIST c i r c l e did ID #REQUIRED>
<! ATTLIST point did ID #REQUIRED>
Example (Circles)
<drawing>
< c i r c l e did= ’C1 ’>
<x>8</ x> <y>8</ y>
<radius>4</ radius>
</ c i r c l e>
<point did= ’P2 ’>
<x>5</ x> <y>5</ y>
</ point>
</ drawing>
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 20 / 37
Uniqueness, Errors
Example (Find the error 1!)
<drawing>
<c i r c l e cid= ’C1 ’ name= ’ f o r e s t ’>
<x>8</ x> <y>8</ y>
<radius>5</ radius>
</ c i r c l e>
<c i r c l e cid= ’C1 ’>
<x>5</ x> <y>5</ y>
<radius u n i t =”cm”>8</ radius>
</ c i r c l e>
</ drawing>
Example (Find the error 2!)
<drawing>
<c i r c l e did= ’C11 ’>
<x>8</ x> <y>8</ y>
<radius>4</ radius>
</ c i r c l e>
<point did= ’C11 ’>
<x>5</ x> <y>5</ y>
</ point>
</ drawing>
Example (Find the error 3!)
<drawing>
<c i r c l e cid= ’C1 ’ name= ’ f o r e s t ’>
<x>8</ x> <y>8</ y>
<radius>5</ radius>
</ c i r c l e>
<c i r c l e cid= ’2C ’>
<x>5</ x> <y>5</ y>
<radius u n i t =”cm”>8</ radius>
</ c i r c l e>
</ drawing>
Example (Find the error 4!)
<drawing>
<c i r c l e did= ’C11 ’>
<x>8</ x> <y>8</ y>
<radius>4</ radius>
</ c i r c l e>
<point did= ’ C1111111111111111111111
<x>5</ x> <y>5</ y>
</ point>
</ drawing>
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 21 / 37
Uniqueness
Limitations
Only attribute values unique not element values
Cannot be a integer, e.g., <circle did=’1’> not allowed
Only unique within a single document
Uniqueness not guaranteed across multiple documents
Only a single attribute uniqueness (no composite keys)
Combination of x and y coordinates cannot be declared unique
Note
Uniqueness quite restrictive compared to DBMS technology
XML Schema lifts most limitations on uniqueness
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 22 / 37
Empty Elements with Attributes
Example (Empty)
<!ELEMENT coor EMPTY>
<! ATTLIST coor cid ID #REQUIRED
x CDATA #REQUIRED
y CDATA #REQUIRED
z CDATA #IMPLIED>
Example (Allowed?)
<coor/>
<coor cid=’c1’ x=’1’ y=’1’ z=’1’/>
<coor cid=’c2’ x=’2’ y=’2’></coor>
<coor cid=’c3’ x=’3’ y=’3’> </coor>
<coor cid=’c4’ z=’4’ y=’4’ x=’4’/>
<coor z=’5’ y=’5’ x=’5’/>
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 23 / 37
Is something Wrong?
Example (Case 1)
<!ELEMENT coor EMPTY>
<! ATTLIST coor
cid ID
x CDATA #REQUIRED>
Example (Case 2!)
<!ELEMENT coor EMPTY>
<! ATTLIST coor
cid ID #IMPLIED
x CDATA #REQUIRED>
Example (Case 3!)
<!ELEMENT coor EMPTY>
<! ATTLIST coor
x CDATA #REQUIRED
cid ID #REQUIRED>
Example (Case 4)
<!ELEMENT coor EMPTY>
<! ATTLIST coor
cid ID ’ 42 ’
x CDATA #REQUIRED>
Example (Case 5)
<!ELEMENT coor (EMPTY)>
<! ATTLIST coor
cid ID #REQUIRED
x CDATA #REQUIRED>
Example (Case 6)
<!ELEMENT coor EMPTY>
<! ATTLIST coor
cid ID #REQUIRED
x ID #REQUIRED>
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 24 / 37
Summary: Attributes
General Syntax
<!ATTLIST element−name attribute−name type [DefaultValue]>
Often used types
Type Example
CDATA <!ATTLIST course id CDATA>
ID <!ATTLIST course id ID #REQUIRED>
Enumeration <!ATTLIST course id (OOP | DB)>
Defaults
Type Example
#REQUIRED <!ATTLIST course id ID #REQUIRED>
#IMPLIED <!ATTLIST course id CDATA #IMPLIED>
#FIXED <!ATTLIST course id CDATA #FIXED ”1”>
A value <!ATTLIST course id (OOP | DB) ”DB”>
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 25 / 37
Outline
1 Introduction
2 Elements
3 Attributes
4 DTD Find Errors
5 Putting it All Together
6 Summary
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 26 / 37
A Buggy DTD
Example (DTD With Five Errors)
<?xml version= ’ 1.0 ’>
<!ELEMENT users user+>
<!ELEMENT user ( firstname , lastname>
<!ELEMENT firstname (#PCDATA)>
<!ELEMENT lastname>
Two-Minutes Exercise
With your neighbor identify the errors in the DTD
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 27 / 37
A Buggy DTD
Example (DTD With Five Errors)
<?xml version= ’ 1.0 ’>
<!ELEMENT users user+>
<!ELEMENT user ( firstname , lastname>
<!ELEMENT firstname (#PCDATA)>
<!ELEMENT lastname>
Two-Minutes Exercise
With your neighbor identify the errors in the DTD
Example (The Corrected DTD)
<?xml version= ’ 1.0 ’ encoding= ’ utf −8 ’?>
<!ELEMENT users ( user )+>
<!ELEMENT user ( firstname , lastname )>
<!ELEMENT firstname (#PCDATA)>
<!ELEMENT lastname (#PCDATA)>
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 27 / 37
Outline
1 Introduction
2 Elements
3 Attributes
4 DTD Find Errors
5 Putting it All Together
6 Summary
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 28 / 37
Uncertain About Content
Example (DTD for Courses with Flexible Description)
<?xml version=” 1.0 ” encoding=”UTF−8” ?>
<!ELEMENT courses ( course )∗>
<!ELEMENT course (name, desc )>
<!ELEMENT name (#PCDATA)>
<!ELEMENT desc ANY>
Example (DTD for Courses with Flexible Description)
<?xml version=” 1.0 ” encoding=”UTF−8” ?>
<!DOCTYPE courses SYSTEM ” course . dtd ”>
<courses>
<course>
<name>OOP</name>
<desc>
<name>object−oriented</name>
<desc>programming</ desc>.
</ desc>
</ course>
</ courses>
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 29 / 37
A University Example, Setup
Example (DTD)
<?xml version=” 1.0 ” encoding=”UTF−8” ?>
<!ELEMENT u n i v e r s i t y ( courses ,
students ,
follows )>
<!ELEMENT courses ( course )+>
<!ELEMENT course (name)>
<! ATTLIST course cid ID #REQUIRED>
<!ELEMENT name (#PCDATA)>
<!ELEMENT students ( student )+>
<!ELEMENT student ( fname )>
<! ATTLIST student sid ID #REQUIRED>
<!ELEMENT fname (#PCDATA)>
<!ELEMENT follows ( takes )+>
<!ELEMENT takes EMPTY>
<! ATTLIST takes sid IDREF #REQUIRED>
<! ATTLIST takes cids IDREFS #REQUIRED>
Example (XML Fragment)
<u n i v e r s i t y>
<courses>
<course cid= ’C111 ’>
<name>DB</name>
</ course>
<course cid= ’C222 ’>
<name>OOP</name>
</ course>
</ courses>
<students>
<student sid= ’S11 ’>
<fname>Ann</ fname>
</ student>
<student sid= ’S22 ’>
<fname>Bart</ fname>
</ student>
<student sid= ’S33 ’>
<fname>Curt</ fname>
</ student>
</ students>
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 30 / 37
A University Example, Referencing
Example (DTD)
<?xml version=” 1.0 ” encoding=”UTF−8” ?>
<!ELEMENT u n i v e r s i t y ( courses ,
students ,
follows )>
<!ELEMENT courses ( course )+>
<!ELEMENT course (name)>
<! ATTLIST course cid ID #REQUIRED>
<!ELEMENT name (#PCDATA)>
<!ELEMENT students ( student )+>
<!ELEMENT student ( fname )>
<! ATTLIST student sid ID #REQUIRED>
<!ELEMENT fname (#PCDATA)>
<!ELEMENT follows ( takes )+>
<!ELEMENT takes EMPTY>
<! ATTLIST takes sid IDREF #REQUIRED>
<! ATTLIST takes cids IDREFS #REQUIRED>
Example (XML Fragment)
<follows>
<takes sid= ’S11 ’ cids= ’C111 C222 ’ />
<takes sid= ’S22 ’ cids= ’C222 ’ />
<takes sid= ’S33 ’ cids= ’C111 ’ />
</ follows>
Note
ID cannot start with digit
sid is a single ID
cids is a set of IDs
No overlap between IDs
Separator is space (not ,)
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 31 / 37
Quiz: IDREFS
Example (University XML)
<u n i v e r s i t y>
<courses>
<course cid= ’C111 ’>
<name>DB</name>
</ course>
<course cid= ’C222 ’>
<name>OOP</name>
</ course>
</ courses>
<students>
<student sid= ’S11 ’>
<fname>Ann</ fname>
</ student>
<student sid= ’S22 ’>
<fname>Bart</ fname>
</ student>
<student sid= ’S33 ’>
<fname>Curt</ fname>
</ student>
</ students>
Example (Allowed One?)
<follows>
<takes sid= ’S11 ’ cids= ’C111 C222 C111 ’ />
</ follows>
Example (Allowed Two?)
<follows>
<takes sid= ’S11 ’ cids= ’C333 C222 C111 ’ />
</ follows>
Example (Allowed Three?)
<follows>
<takes sid= ’S11 ’ cids= ’C111 ’ />
<takes sid= ’S11 ’ cids= ’C222 ’ />
</ follows>
Example (Allowed Four?)
<follows>
<takes sid= ’S11 ’ cids= ’ ’ />
<takes sid= ’S22 ’ cids= ’ c111 ’ />
</ follows>
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 32 / 37
Using an Internal DTD
Example (DTD for Courses with Flexible Description)
<?xml version=” 1.0 ” standalone=” yes ” ?>
<!DOCTYPE courses [
<!ELEMENT courses ( course )∗>
<!ELEMENT course (name, desc )>
<!ELEMENT name (#PCDATA)>
<!ELEMENT desc ANY>
]>
<courses>
<course>
<name>OOP</name>
<desc>
<name>object−oriented</name>
<desc>programming</ desc>.
</ desc>
</ course>
</ courses>
Note
Benefit: All information in one file
Drawback: DTD is not reused (maintenance nightmare)
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 33 / 37
Outline
1 Introduction
2 Elements
3 Attributes
4 DTD Find Errors
5 Putting it All Together
6 Summary
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 34 / 37
Summary: DTD
Limitations
Only very basic data types supported
Only single-column keys (for uniqueness)
Uniqueness only guaranteed within a single document
Very limited support for integrity constraints
Note
DTD is widely used
DTD is being replaced by XML Schema when documents are complex
There are problems using XML Namespace and DTD
Advise
Never build a new DTD if an existing (standard) can be used!
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 35 / 37
RDBMS vs. XML
RDBMS vs. XML
Query Schema
SQL DML DDL
XML XQuery DTD/XML Schema
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 36 / 37
Summary: DTD versus XML Schema
DTD
Own format
Compact notation
Simple data types
From SGML
Support entities
No support namespaces
XML Schema
XML format
Very verbose
Advanced data types
Invented for XML
Does not support entities
Support namespaces
Advice
Start with a DTD
Move on to XML Schema for later iterations
Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 37 / 37

More Related Content

What's hot

XML Schema
XML SchemaXML Schema
XML Schema
yht4ever
 
Document type definition
Document type definitionDocument type definition
Document type definition
Raghu nath
 
XML, DTD & XSD Overview
XML, DTD & XSD OverviewXML, DTD & XSD Overview
XML, DTD & XSD Overview
Pradeep Rapolu
 
4 xml namespaces and xml schema
4   xml namespaces and xml schema4   xml namespaces and xml schema
4 xml namespaces and xml schema
gauravashq
 
3 xml namespaces and xml schema
3   xml namespaces and xml schema3   xml namespaces and xml schema
3 xml namespaces and xml schema
gauravashq
 
Xml dtd
Xml dtdXml dtd
Xml dtd
HeenaRajput1
 
Dtd
DtdDtd
01 xml document structure
01 xml document structure01 xml document structure
01 xml document structure
Baskarkncet
 
XML's validation - XML Schema
XML's validation - XML SchemaXML's validation - XML Schema
XML's validation - XML Schema
videde_group
 
XML and DTD
XML and DTDXML and DTD
XML and DTD
Jussi Pohjolainen
 
Document Type Definition
Document Type DefinitionDocument Type Definition
Document Type Definition
yht4ever
 
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
Marek Maśko
 
XSD
XSDXSD
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
yht4ever
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
Abhra Basak
 
Introduction to xml
Introduction to xmlIntroduction to xml
Introduction to xml
Gtu Booker
 
02 xml schema
02 xml schema02 xml schema
02 xml schema
Baskarkncet
 
Xml schema
Xml schemaXml schema
Xml schema
Akshaya Akshaya
 
Xml basics
Xml basicsXml basics
Xml basics
Kumar
 
Xml Java
Xml JavaXml Java
Xml Java
cbee48
 

What's hot (20)

XML Schema
XML SchemaXML Schema
XML Schema
 
Document type definition
Document type definitionDocument type definition
Document type definition
 
XML, DTD & XSD Overview
XML, DTD & XSD OverviewXML, DTD & XSD Overview
XML, DTD & XSD Overview
 
4 xml namespaces and xml schema
4   xml namespaces and xml schema4   xml namespaces and xml schema
4 xml namespaces and xml schema
 
3 xml namespaces and xml schema
3   xml namespaces and xml schema3   xml namespaces and xml schema
3 xml namespaces and xml schema
 
Xml dtd
Xml dtdXml dtd
Xml dtd
 
Dtd
DtdDtd
Dtd
 
01 xml document structure
01 xml document structure01 xml document structure
01 xml document structure
 
XML's validation - XML Schema
XML's validation - XML SchemaXML's validation - XML Schema
XML's validation - XML Schema
 
XML and DTD
XML and DTDXML and DTD
XML and DTD
 
Document Type Definition
Document Type DefinitionDocument Type Definition
Document Type Definition
 
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
 
XSD
XSDXSD
XSD
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
Introduction to xml
Introduction to xmlIntroduction to xml
Introduction to xml
 
02 xml schema
02 xml schema02 xml schema
02 xml schema
 
Xml schema
Xml schemaXml schema
Xml schema
 
Xml basics
Xml basicsXml basics
Xml basics
 
Xml Java
Xml JavaXml Java
Xml Java
 

Similar to Introduction to DTD

Introduction to XML and Databases
Introduction to XML and DatabasesIntroduction to XML and Databases
Introduction to XML and Databases
torp42
 
Introduction to XPath
Introduction to XPathIntroduction to XPath
Introduction to XPath
torp42
 
SQL/XML on Oracle
SQL/XML on OracleSQL/XML on Oracle
SQL/XML on Oracle
torp42
 
XML on SQL Server
XML on SQL ServerXML on SQL Server
XML on SQL Server
torp42
 
Digital + Container List
Digital + Container ListDigital + Container List
Digital + Container List
guest53eac8
 
Xml 20111006 hurd
Xml 20111006 hurdXml 20111006 hurd
Xml 20111006 hurd
carishurd
 
[Km] [wp] [3] [assignment]
[Km] [wp] [3] [assignment][Km] [wp] [3] [assignment]
[Km] [wp] [3] [assignment]
Azam Charaniya
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
Dr. C.V. Suresh Babu
 
Training in Analytics, R and Social Media Analytics
Training in Analytics, R and Social Media AnalyticsTraining in Analytics, R and Social Media Analytics
Training in Analytics, R and Social Media Analytics
Ajay Ohri
 
XML
XMLXML
Xml and Co.
Xml and Co.Xml and Co.
Xml and Co.
Findik Dervis
 
Innovative way for normalizing xml document
Innovative way for normalizing xml documentInnovative way for normalizing xml document
Innovative way for normalizing xml document
Alexander Decker
 
Decoding and developing the online finding aid
Decoding and developing the online finding aidDecoding and developing the online finding aid
Decoding and developing the online finding aid
kgerber
 
Xml Lecture Notes
Xml Lecture NotesXml Lecture Notes
Xml Lecture Notes
Santhiya Grace
 
distributed system concerned lab sessions
distributed system concerned lab sessionsdistributed system concerned lab sessions
distributed system concerned lab sessions
milkesa13
 
Web forms and html lecture Number 3
Web forms and html lecture Number 3Web forms and html lecture Number 3
Web forms and html lecture Number 3
Mudasir Syed
 
Lambdas myths-and-mistakes
Lambdas myths-and-mistakesLambdas myths-and-mistakes
Lambdas myths-and-mistakes
RichardWarburton
 
Lambda Expressions: Myths and Mistakes - Richard Warburton (jClarity)
Lambda Expressions: Myths and Mistakes - Richard Warburton (jClarity)Lambda Expressions: Myths and Mistakes - Richard Warburton (jClarity)
Lambda Expressions: Myths and Mistakes - Richard Warburton (jClarity)
jaxLondonConference
 
EAD Revision Progress Report, SAA 2013
EAD Revision Progress Report, SAA 2013EAD Revision Progress Report, SAA 2013
EAD Revision Progress Report, SAA 2013
Michael Rush
 
XPath - XML Path Language
XPath - XML Path LanguageXPath - XML Path Language
XPath - XML Path Language
yht4ever
 

Similar to Introduction to DTD (20)

Introduction to XML and Databases
Introduction to XML and DatabasesIntroduction to XML and Databases
Introduction to XML and Databases
 
Introduction to XPath
Introduction to XPathIntroduction to XPath
Introduction to XPath
 
SQL/XML on Oracle
SQL/XML on OracleSQL/XML on Oracle
SQL/XML on Oracle
 
XML on SQL Server
XML on SQL ServerXML on SQL Server
XML on SQL Server
 
Digital + Container List
Digital + Container ListDigital + Container List
Digital + Container List
 
Xml 20111006 hurd
Xml 20111006 hurdXml 20111006 hurd
Xml 20111006 hurd
 
[Km] [wp] [3] [assignment]
[Km] [wp] [3] [assignment][Km] [wp] [3] [assignment]
[Km] [wp] [3] [assignment]
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
Training in Analytics, R and Social Media Analytics
Training in Analytics, R and Social Media AnalyticsTraining in Analytics, R and Social Media Analytics
Training in Analytics, R and Social Media Analytics
 
XML
XMLXML
XML
 
Xml and Co.
Xml and Co.Xml and Co.
Xml and Co.
 
Innovative way for normalizing xml document
Innovative way for normalizing xml documentInnovative way for normalizing xml document
Innovative way for normalizing xml document
 
Decoding and developing the online finding aid
Decoding and developing the online finding aidDecoding and developing the online finding aid
Decoding and developing the online finding aid
 
Xml Lecture Notes
Xml Lecture NotesXml Lecture Notes
Xml Lecture Notes
 
distributed system concerned lab sessions
distributed system concerned lab sessionsdistributed system concerned lab sessions
distributed system concerned lab sessions
 
Web forms and html lecture Number 3
Web forms and html lecture Number 3Web forms and html lecture Number 3
Web forms and html lecture Number 3
 
Lambdas myths-and-mistakes
Lambdas myths-and-mistakesLambdas myths-and-mistakes
Lambdas myths-and-mistakes
 
Lambda Expressions: Myths and Mistakes - Richard Warburton (jClarity)
Lambda Expressions: Myths and Mistakes - Richard Warburton (jClarity)Lambda Expressions: Myths and Mistakes - Richard Warburton (jClarity)
Lambda Expressions: Myths and Mistakes - Richard Warburton (jClarity)
 
EAD Revision Progress Report, SAA 2013
EAD Revision Progress Report, SAA 2013EAD Revision Progress Report, SAA 2013
EAD Revision Progress Report, SAA 2013
 
XPath - XML Path Language
XPath - XML Path LanguageXPath - XML Path Language
XPath - XML Path Language
 

More from torp42

The DE-9IM Matrix in Details using ST_Relate: In Picture and SQL
The DE-9IM Matrix in Details using ST_Relate: In Picture and SQLThe DE-9IM Matrix in Details using ST_Relate: In Picture and SQL
The DE-9IM Matrix in Details using ST_Relate: In Picture and SQL
torp42
 
Spatial Indexing
Spatial IndexingSpatial Indexing
Spatial Indexing
torp42
 
Entity-Relationship Diagrams ERD
Entity-Relationship Diagrams ERDEntity-Relationship Diagrams ERD
Entity-Relationship Diagrams ERD
torp42
 
Temporal Databases: Data Models
Temporal Databases: Data ModelsTemporal Databases: Data Models
Temporal Databases: Data Models
torp42
 
Temporal Databases: Modifications
Temporal Databases: ModificationsTemporal Databases: Modifications
Temporal Databases: Modifications
torp42
 
Temporal Databases: Queries
Temporal Databases: QueriesTemporal Databases: Queries
Temporal Databases: Queries
torp42
 

More from torp42 (6)

The DE-9IM Matrix in Details using ST_Relate: In Picture and SQL
The DE-9IM Matrix in Details using ST_Relate: In Picture and SQLThe DE-9IM Matrix in Details using ST_Relate: In Picture and SQL
The DE-9IM Matrix in Details using ST_Relate: In Picture and SQL
 
Spatial Indexing
Spatial IndexingSpatial Indexing
Spatial Indexing
 
Entity-Relationship Diagrams ERD
Entity-Relationship Diagrams ERDEntity-Relationship Diagrams ERD
Entity-Relationship Diagrams ERD
 
Temporal Databases: Data Models
Temporal Databases: Data ModelsTemporal Databases: Data Models
Temporal Databases: Data Models
 
Temporal Databases: Modifications
Temporal Databases: ModificationsTemporal Databases: Modifications
Temporal Databases: Modifications
 
Temporal Databases: Queries
Temporal Databases: QueriesTemporal Databases: Queries
Temporal Databases: Queries
 

Recently uploaded

Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
Pixlogix Infotech
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 

Recently uploaded (20)

Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 

Introduction to DTD

  • 1. Introduction to DTD Kristian Torp Department of Computer Science Aalborg University people.cs.aau.dk/˜torp torp@cs.aau.dk November 3, 2015 daisy.aau.dk Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 1 / 37
  • 2. Outline 1 Introduction 2 Elements 3 Attributes 4 DTD Find Errors 5 Putting it All Together 6 Summary Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 2 / 37
  • 3. Learning Outcomes Learning Outcomes Be able to read and understand a DTD Be able to construct a DTD for a set of existing XML documents Be able to validate an XML document against a DTD Know the limitations of a DTD Database Focus All XML technologies are presented from a database perspective! Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 3 / 37
  • 4. Outline 1 Introduction 2 Elements 3 Attributes 4 DTD Find Errors 5 Putting it All Together 6 Summary Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 4 / 37
  • 5. Example: Course Catalog XML Document User Requirements Make a DTD for the course catalog Use the DTD to validate our course catalog XML document Example (Current Courses) <?xml version=” 1.0 ” ?> <coursecatalog> <course cid= ’P4 ’> <name>OOP</name> <semester>3</ semester> <desc>Object−oriented programming</ desc> </ course> <course cid= ’P2 ’> <name>DB</name> <semester>7</ semester> <desc>Databases including SQL</ desc> </ course> </ coursecatalog> Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 5 / 37
  • 6. Example: Course Catalog DTD Example (DTD for Course Catalog) <?xml version=” 1.0 ” encoding=”UTF−8” ?> <!ELEMENT coursecatalog ( course )∗> <!ELEMENT course (name, semester , desc ) > <!ELEMENT name (#PCDATA)> <!ELEMENT semester (#PCDATA)> <!ELEMENT desc (#PCDATA)> <! ATTLIST course cid ID #REQUIRED> Informal Description A course catalog consists of zero or more of courses A course consists of a name, a semester, and a description It is identified by an ID that is required A (course) name is a string (leaf in XML document) A semester is a string (leaf in XML document) A description is a string (leaf in XML document) Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 6 / 37
  • 7. Overview Purpose Define the document structure Legal elements and attributes Serves the same purpose as a create table statement in SQL Structure and type of data Integrity constraints! Left over from SGML Is not written in XML If this is a requirement then use XML Schema Still very widely used Because much simpler than XML Schema Note Many simple errors can be found using a DTD A necessity if receiving XML documents from external sources Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 7 / 37
  • 8. Outline 1 Introduction 2 Elements 3 Attributes 4 DTD Find Errors 5 Putting it All Together 6 Summary Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 8 / 37
  • 9. Simplest Entity Example (Element Declaration) <!ELEMENT name (#PCDATA)> Example (Allowed Values) <name>Hello Element</name> <name/> <name><![CDATA[ select ∗ from emp where sal > 10]]></name> Example (Illegal Values) <name>> </name> <name>&gt;</name> <name><it>Hello</it></name> Unknown element <it>, must be defined in DTD Note Root, internal-node, and leafs in XML tree representation Terminal and non-terminal in grammar terminology Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 9 / 37
  • 10. Sequences of Child Elements Example (Element Declaration) <!ELEMENT course (name, semester, desc)> Example (Allowed XML Fragment, Why?) <course> <name>OOP</name> <semester>7</ semester> <desc>I n t r o d u c t i o n to OOP</ desc> </ course> Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 10 / 37
  • 11. Sequences of Child Elements Example (Element Declaration) <!ELEMENT course (name, semester, desc)> Example (Allowed XML Fragment, Why?) <course> <name>OOP</name> <semester>7</ semester> <desc>I n t r o d u c t i o n to OOP</ desc> </ course> Example (Disallowed XML Fragment, Why?) <course> <semester>7</ semester> <name>OOP</name> </ course> Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 10 / 37
  • 12. Sequences of Child Elements Example (Element Declaration) <!ELEMENT course (name, semester, desc)> Example (Allowed XML Fragment, Why?) <course> <name>OOP</name> <semester>7</ semester> <desc>I n t r o d u c t i o n to OOP</ desc> </ course> Example (Disallowed XML Fragment, Why?) <course> <semester>7</ semester> <name>OOP</name> </ course> Example (Is this allowed?) <course></ course> Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 10 / 37
  • 13. Choice Among Child Elements Example (Element Declaration) <!ELEMENT circle (x, y, (radius | diameter))> Example (Allowed XML Fragment) < c i r c l e> <x>5</ x> <y>9</ y> <diameter>7</ diameter> </ c i r c l e> Example (Illegal XML Fragment) < c i r c l e> <x>4</ x> <y>8</ y> <radius>3.5</ radius> <diameter>7</ diameter> </ c i r c l e> Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 11 / 37
  • 14. Symbols in a DTD Symbols Symbol Example ∗ <!ELEMENT coursecatalog (course)∗> + <!ELEMENT coursecatalog (course)+> ? <!ELEMENT coursecatalog (course)?> , <!ELEMENT course (name, semester, desc) > | <!ELEMENT course (name | semester | desc) > Note Symbols are mostly taken from regular expressions Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 12 / 37
  • 15. Mixed Content Example (Data Centric) <!ELEMENT coor ( x , y )> Example (Allowed Fragment) <coor> <x>5</ x> <y>9</ y> </ coor> Example (Mixed Content) <!ELEMENT coor ( x , y , #PCDATA)∗> Example (Allowed Fragment) <coor> This i s the coordinate (<x>5</ x> , <y>9</ y>) where the treasure i s hidden ! </ coor> Note Data centric very table like Mixed content also called narrative document Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 13 / 37
  • 16. Element Declarations using ANY Example (Any) <!ELEMENT coor (ANY)> <!ELEMENT x (#PCDATA) <!ELEMENT y (#PCDATA) Example (Allowed Fragments) <coor/> <coor>Hello World</coor> <coor>Hello <x>1</x><x/>World<y>3</y><y>4</y></coor> <coor>Hello <x>1</x><y>2</y>World<y>3</y><x>4</x></coor> Example (Illegal Fragments) <coor><z>1</z></coor> <coor><x>1</x><y>1<y/><z>1</z></coor> Note ANY handy for narrative documents, e.g., HTML Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 14 / 37
  • 17. Element Declarations using EMPTY Example (Empty) <!ELEMENT coor EMPTY> Example (Allowed?) <coor></coor> <coor/> <coor>Hello</coor> <coor><x>Hello</x></coor> <coor> </coor> Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 15 / 37
  • 18. Summary: Elements Repetition Symbol Explanation Example ? zero-or-one <!ELEMENT person (address?)> * zero-or-more <!ELEMENT person (address∗)> + one-or-more <!ELEMENT person (address+)> once <!ELEMENT person (address)> Sequence or Choice Symbol Explanation Example , Sequence <!ELEMENT coor (x, y)> | Choice <!ELEMENT coor (x | y)> Data Type Symbol Explanation Example #PCDATA String <!ELEMENT name (#PCDATA)> ANY What ever <!ELEMENT coor (ANY)> EMPTY Empty <!ELEMENT room EMPTY> Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 16 / 37
  • 19. Outline 1 Introduction 2 Elements 3 Attributes 4 DTD Find Errors 5 Putting it All Together 6 Summary Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 17 / 37
  • 20. Attribute Declarations Example (Circles) <?xml version= ’ 1.0 ’ encoding= ’ utf −8 ’?> <!ELEMENT drawing ( c i r c l e )∗> <!ELEMENT c i r c l e ( x , y , ( radius | diameter ) )> <! ATTLIST c i r c l e cid ID #REQUIRED name CDATA #IMPLIED > <!ELEMENT x (#PCDATA)> <!ELEMENT y (#PCDATA)> <!ELEMENT radius (#PCDATA)> <! ATTLIST radius u n i t (mm|cm |m) ”m”> <!−− Enum with default −−> <!ELEMENT diameter (#PCDATA)> <! ATTLIST diameter u n i t (mm|cm |m) #REQUIRED> <!−− Enum no default −−> Note Mandatory and optional attributes One or more attributes Enumeration with defaults Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 18 / 37
  • 21. Example Document Example (Circles) <?xml version=” 1.0 ” encoding= ’UTF−8 ’?> <!DOCTYPE drawing SYSTEM ” c i r c l e a t t . dtd ”> <drawing> < c i r c l e cid= ’C1 ’ name= ’ f o r e s t ’> <x>8</ x> <y>8</ y> <radius>4</ radius> <!−− default u n i t−−> </ c i r c l e> < c i r c l e cid= ’C2 ’> <!−− name not required −−> <x>5</ x> <y>5</ y> <radius u n i t =”cm”>4</ radius> <!−− e x p l i c i t u n i t−−> </ c i r c l e> </ drawing> Note Unique value is not an integer Used that attribute name is optional in element circle Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 19 / 37
  • 22. Uniqueness, Examples Example (Circle/Points with IDs) <?xml version= ’ 1.0 ’ encoding= ’ utf −8 ’?> <!ELEMENT drawing ( point | c i r c l e )∗> <!ELEMENT point ( x , y )> <!ELEMENT c i r c l e ( x , y , ( radius | diameter ) )> <! ATTLIST c i r c l e did ID #REQUIRED> <! ATTLIST point did ID #REQUIRED> Example (Circles) <drawing> < c i r c l e did= ’C1 ’> <x>8</ x> <y>8</ y> <radius>4</ radius> </ c i r c l e> <point did= ’P2 ’> <x>5</ x> <y>5</ y> </ point> </ drawing> Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 20 / 37
  • 23. Uniqueness, Errors Example (Find the error 1!) <drawing> <c i r c l e cid= ’C1 ’ name= ’ f o r e s t ’> <x>8</ x> <y>8</ y> <radius>5</ radius> </ c i r c l e> <c i r c l e cid= ’C1 ’> <x>5</ x> <y>5</ y> <radius u n i t =”cm”>8</ radius> </ c i r c l e> </ drawing> Example (Find the error 2!) <drawing> <c i r c l e did= ’C11 ’> <x>8</ x> <y>8</ y> <radius>4</ radius> </ c i r c l e> <point did= ’C11 ’> <x>5</ x> <y>5</ y> </ point> </ drawing> Example (Find the error 3!) <drawing> <c i r c l e cid= ’C1 ’ name= ’ f o r e s t ’> <x>8</ x> <y>8</ y> <radius>5</ radius> </ c i r c l e> <c i r c l e cid= ’2C ’> <x>5</ x> <y>5</ y> <radius u n i t =”cm”>8</ radius> </ c i r c l e> </ drawing> Example (Find the error 4!) <drawing> <c i r c l e did= ’C11 ’> <x>8</ x> <y>8</ y> <radius>4</ radius> </ c i r c l e> <point did= ’ C1111111111111111111111 <x>5</ x> <y>5</ y> </ point> </ drawing> Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 21 / 37
  • 24. Uniqueness Limitations Only attribute values unique not element values Cannot be a integer, e.g., <circle did=’1’> not allowed Only unique within a single document Uniqueness not guaranteed across multiple documents Only a single attribute uniqueness (no composite keys) Combination of x and y coordinates cannot be declared unique Note Uniqueness quite restrictive compared to DBMS technology XML Schema lifts most limitations on uniqueness Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 22 / 37
  • 25. Empty Elements with Attributes Example (Empty) <!ELEMENT coor EMPTY> <! ATTLIST coor cid ID #REQUIRED x CDATA #REQUIRED y CDATA #REQUIRED z CDATA #IMPLIED> Example (Allowed?) <coor/> <coor cid=’c1’ x=’1’ y=’1’ z=’1’/> <coor cid=’c2’ x=’2’ y=’2’></coor> <coor cid=’c3’ x=’3’ y=’3’> </coor> <coor cid=’c4’ z=’4’ y=’4’ x=’4’/> <coor z=’5’ y=’5’ x=’5’/> Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 23 / 37
  • 26. Is something Wrong? Example (Case 1) <!ELEMENT coor EMPTY> <! ATTLIST coor cid ID x CDATA #REQUIRED> Example (Case 2!) <!ELEMENT coor EMPTY> <! ATTLIST coor cid ID #IMPLIED x CDATA #REQUIRED> Example (Case 3!) <!ELEMENT coor EMPTY> <! ATTLIST coor x CDATA #REQUIRED cid ID #REQUIRED> Example (Case 4) <!ELEMENT coor EMPTY> <! ATTLIST coor cid ID ’ 42 ’ x CDATA #REQUIRED> Example (Case 5) <!ELEMENT coor (EMPTY)> <! ATTLIST coor cid ID #REQUIRED x CDATA #REQUIRED> Example (Case 6) <!ELEMENT coor EMPTY> <! ATTLIST coor cid ID #REQUIRED x ID #REQUIRED> Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 24 / 37
  • 27. Summary: Attributes General Syntax <!ATTLIST element−name attribute−name type [DefaultValue]> Often used types Type Example CDATA <!ATTLIST course id CDATA> ID <!ATTLIST course id ID #REQUIRED> Enumeration <!ATTLIST course id (OOP | DB)> Defaults Type Example #REQUIRED <!ATTLIST course id ID #REQUIRED> #IMPLIED <!ATTLIST course id CDATA #IMPLIED> #FIXED <!ATTLIST course id CDATA #FIXED ”1”> A value <!ATTLIST course id (OOP | DB) ”DB”> Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 25 / 37
  • 28. Outline 1 Introduction 2 Elements 3 Attributes 4 DTD Find Errors 5 Putting it All Together 6 Summary Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 26 / 37
  • 29. A Buggy DTD Example (DTD With Five Errors) <?xml version= ’ 1.0 ’> <!ELEMENT users user+> <!ELEMENT user ( firstname , lastname> <!ELEMENT firstname (#PCDATA)> <!ELEMENT lastname> Two-Minutes Exercise With your neighbor identify the errors in the DTD Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 27 / 37
  • 30. A Buggy DTD Example (DTD With Five Errors) <?xml version= ’ 1.0 ’> <!ELEMENT users user+> <!ELEMENT user ( firstname , lastname> <!ELEMENT firstname (#PCDATA)> <!ELEMENT lastname> Two-Minutes Exercise With your neighbor identify the errors in the DTD Example (The Corrected DTD) <?xml version= ’ 1.0 ’ encoding= ’ utf −8 ’?> <!ELEMENT users ( user )+> <!ELEMENT user ( firstname , lastname )> <!ELEMENT firstname (#PCDATA)> <!ELEMENT lastname (#PCDATA)> Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 27 / 37
  • 31. Outline 1 Introduction 2 Elements 3 Attributes 4 DTD Find Errors 5 Putting it All Together 6 Summary Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 28 / 37
  • 32. Uncertain About Content Example (DTD for Courses with Flexible Description) <?xml version=” 1.0 ” encoding=”UTF−8” ?> <!ELEMENT courses ( course )∗> <!ELEMENT course (name, desc )> <!ELEMENT name (#PCDATA)> <!ELEMENT desc ANY> Example (DTD for Courses with Flexible Description) <?xml version=” 1.0 ” encoding=”UTF−8” ?> <!DOCTYPE courses SYSTEM ” course . dtd ”> <courses> <course> <name>OOP</name> <desc> <name>object−oriented</name> <desc>programming</ desc>. </ desc> </ course> </ courses> Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 29 / 37
  • 33. A University Example, Setup Example (DTD) <?xml version=” 1.0 ” encoding=”UTF−8” ?> <!ELEMENT u n i v e r s i t y ( courses , students , follows )> <!ELEMENT courses ( course )+> <!ELEMENT course (name)> <! ATTLIST course cid ID #REQUIRED> <!ELEMENT name (#PCDATA)> <!ELEMENT students ( student )+> <!ELEMENT student ( fname )> <! ATTLIST student sid ID #REQUIRED> <!ELEMENT fname (#PCDATA)> <!ELEMENT follows ( takes )+> <!ELEMENT takes EMPTY> <! ATTLIST takes sid IDREF #REQUIRED> <! ATTLIST takes cids IDREFS #REQUIRED> Example (XML Fragment) <u n i v e r s i t y> <courses> <course cid= ’C111 ’> <name>DB</name> </ course> <course cid= ’C222 ’> <name>OOP</name> </ course> </ courses> <students> <student sid= ’S11 ’> <fname>Ann</ fname> </ student> <student sid= ’S22 ’> <fname>Bart</ fname> </ student> <student sid= ’S33 ’> <fname>Curt</ fname> </ student> </ students> Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 30 / 37
  • 34. A University Example, Referencing Example (DTD) <?xml version=” 1.0 ” encoding=”UTF−8” ?> <!ELEMENT u n i v e r s i t y ( courses , students , follows )> <!ELEMENT courses ( course )+> <!ELEMENT course (name)> <! ATTLIST course cid ID #REQUIRED> <!ELEMENT name (#PCDATA)> <!ELEMENT students ( student )+> <!ELEMENT student ( fname )> <! ATTLIST student sid ID #REQUIRED> <!ELEMENT fname (#PCDATA)> <!ELEMENT follows ( takes )+> <!ELEMENT takes EMPTY> <! ATTLIST takes sid IDREF #REQUIRED> <! ATTLIST takes cids IDREFS #REQUIRED> Example (XML Fragment) <follows> <takes sid= ’S11 ’ cids= ’C111 C222 ’ /> <takes sid= ’S22 ’ cids= ’C222 ’ /> <takes sid= ’S33 ’ cids= ’C111 ’ /> </ follows> Note ID cannot start with digit sid is a single ID cids is a set of IDs No overlap between IDs Separator is space (not ,) Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 31 / 37
  • 35. Quiz: IDREFS Example (University XML) <u n i v e r s i t y> <courses> <course cid= ’C111 ’> <name>DB</name> </ course> <course cid= ’C222 ’> <name>OOP</name> </ course> </ courses> <students> <student sid= ’S11 ’> <fname>Ann</ fname> </ student> <student sid= ’S22 ’> <fname>Bart</ fname> </ student> <student sid= ’S33 ’> <fname>Curt</ fname> </ student> </ students> Example (Allowed One?) <follows> <takes sid= ’S11 ’ cids= ’C111 C222 C111 ’ /> </ follows> Example (Allowed Two?) <follows> <takes sid= ’S11 ’ cids= ’C333 C222 C111 ’ /> </ follows> Example (Allowed Three?) <follows> <takes sid= ’S11 ’ cids= ’C111 ’ /> <takes sid= ’S11 ’ cids= ’C222 ’ /> </ follows> Example (Allowed Four?) <follows> <takes sid= ’S11 ’ cids= ’ ’ /> <takes sid= ’S22 ’ cids= ’ c111 ’ /> </ follows> Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 32 / 37
  • 36. Using an Internal DTD Example (DTD for Courses with Flexible Description) <?xml version=” 1.0 ” standalone=” yes ” ?> <!DOCTYPE courses [ <!ELEMENT courses ( course )∗> <!ELEMENT course (name, desc )> <!ELEMENT name (#PCDATA)> <!ELEMENT desc ANY> ]> <courses> <course> <name>OOP</name> <desc> <name>object−oriented</name> <desc>programming</ desc>. </ desc> </ course> </ courses> Note Benefit: All information in one file Drawback: DTD is not reused (maintenance nightmare) Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 33 / 37
  • 37. Outline 1 Introduction 2 Elements 3 Attributes 4 DTD Find Errors 5 Putting it All Together 6 Summary Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 34 / 37
  • 38. Summary: DTD Limitations Only very basic data types supported Only single-column keys (for uniqueness) Uniqueness only guaranteed within a single document Very limited support for integrity constraints Note DTD is widely used DTD is being replaced by XML Schema when documents are complex There are problems using XML Namespace and DTD Advise Never build a new DTD if an existing (standard) can be used! Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 35 / 37
  • 39. RDBMS vs. XML RDBMS vs. XML Query Schema SQL DML DDL XML XQuery DTD/XML Schema Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 36 / 37
  • 40. Summary: DTD versus XML Schema DTD Own format Compact notation Simple data types From SGML Support entities No support namespaces XML Schema XML format Very verbose Advanced data types Invented for XML Does not support entities Support namespaces Advice Start with a DTD Move on to XML Schema for later iterations Kristian Torp (Aalborg University) Introduction to DTD November 3, 2015 37 / 37