SlideShare a Scribd company logo
1 of 28
Document Type Definitions XML
DTD stands for Document Type Definition Allows an XML document to go further than meeting the requirements of being well-formed Specifies requirements to be valid A valid XML document matches definitions of allowable elements, attributes DTD Overview
Validation can be done in code (i.e. using javascript, VB and DOM) DTD’s allow use of a validating parser that compares the document against specifications Typically makes application changes and maintenance easier Less tied to a particular programming language/environment Validation
Declarations are used to specify document requirements Document type declaration Element declaration Attribute List declaration Entity declaration Declarations
Includes name of root element Allows specification of where the DTD is located DTD can be embedded in the XML file (local) DTD can refer to external file, Uniform Resource Identifier (URI) Local takes precedence over external Document Type Declaration
Element Declaration has 3 parts: Declaration Element name Element content Element content can include a list of child elements or data Element Declaration
DTD included in XML document Definition of a student: <!DOCTYPE student[ <!ELEMENT student(first, last, studentID)> <!ELEMENT first (#PCDATA)> <!ELEMENT last(#PCDATA)> <ELEMENT studentID(#PCDATA)> ]> LocalDTD Document Type Declaration Element Declaration A student element is made up of first name, last name, and student id elements
DTD exists in external file/location Must use keyword to specify type of location SYSTEM is a reference to local file system PUBLIC is reference to DTD accessed through a catalog Can use both together If can’t find catalog reference can use specified file External Definition
Reference in XML file: <!DOCTYPE student SYSTEM “student.dtd”> External file: <!ELEMENT student(first, last, studentID)> <!ELEMENT first (#PCDATA)> <!ELEMENT last(#PCDATA)> <ELEMENT studentID(#PCDATA)> ]> Sample External Definition Document Type Declaration Element Declaration
Element name must match name in XML document If using namespaces, prefixes must match Content Model defines what the element can store An element Mixed (i.e. data and element) Empty Any Working With Elements
One element can contain another Can specify the elements contained by sequence Can specify the elements contained as a choice Element Content
Error raised if an element is missing Error raised if there are extra elements Error raised if elements in a different order For a student, our content must be in firstname, lastname, studentID order If find an element “major”, error If order varies, error If missing first, last, or studentID, error Content by Sequence
Can allow content to vary between elements | (vertical bar or pipe) indicates OR If  add a Grade element to a student that can be a letter or percent: <!ELEMENT grade (letter | percent)> <!ELEMENT letter (#PCDATA)> <!ELEMENT percent (#PCDATA) Indicates that must have letter or percent element   Content by Choice
A name may be a full name (first, middle, last) or just first and last: <!ELEMENT name (fullName | (first, last))> <!ELEMENT fullName (first, middle, last)> <!ELEMENT first (#PCDATA)> <!ELEMENT middle (#PCDATA)> <!ELEMENT last (#PCDATA)> By Choice: Example
Allows combination of elements and parsed character data Can include additional information within an element, eg. how to display Rules: Managed by using Choice (or) PCDATA must appear first in list of elements List cannot include inner content model (only simple elements) If there are child elements, include *  * Indicates that may appear zero or more times Mixed Content
If want to include emphasis with the letter grade Data: <letter><em>4</em></letter> Declaration: <!ELEMENT letter (#PCDATA | em)*> Describes a letter element as the content (pcdata) plus emphasis element Mixed Content -2
An element can be empty <br /> (never has child, content) Declaration includes EMPTY: <!ELEMENT br EMPTY> Means that the element CANNOT contain content Empty Content
An element can contain any kind of value (or be empty) Any elements declared in the DTD can occur, any number of times Only elements that are part of the DTD can be part of the document! May be empty May contain PCDATA Least restrictive model Any Content
How many times can an element occur? How many times must an element occur? Cardinality
A student must have a first name A student may or may not have a last name A student may have one or more majors, or none (undeclared) 	<!ELEMENT student (first, last?, major*)> Note: Cardinality indicator doesn’t affect the element declaration (i.e. major) Cardinality: Example
Elements tend to be used to describe a logical unit of information Attributes are typically used to store data about characteristics (properties) May have a Movie element with attributes for Title, Rental Price, Rental Days No specific rules about how to use elements and attributes Attributes and DTD’s
Attributes allow more limits on data Can have a list of acceptable values Can have a default value Some ability to specify a data type Concise, about a single name/value pair Attributes have limits Can’t store long strings of text Can’t nest values Whitespace can’t be ignored Attributes and Elements
Declaration: <!ATTLISTElementNameAttrNameAttrType Default> Specify the Element the attribute belongs to Specify the Name of the attribute Specify the Type of data the attribute stores Specify characteristics of the values (Default or attribute value) List either the default value or other characteristic of value – required, optional Specifying Attributes
CDATA – unparsed character data Enumerated – series/list of string values Entity/Entities – reference entity definition(s) ID – unique identifier for the element IDREF – refer to the ID of another element IDREFS – list of ID’s of other elements separated by whitespace NMTOKEN/NMTOKENS – value(s) of attribute can be anything that follows rules for XML name Sample Attribute Data Types
Specifies that attribute value must be found in a particular list Each value in list must be valid XML name Limits on spaces, characters Use | (pipe) to separate members of list If specifying list letter grades for a student: <!ATTLIST student grade (A | B | C | D | F | V | W | I) #IMPLIED> Enumerated Attributes Element Attribute Enumerated List
An ID specifies that the element must have a unique value within the document Allows reliable way to refer to a specific element No spaces allowed in value Typically replace space with underscore Attribute list can include only one ID IDREF, IDREFS allows an element to be associated with another or multiple other elements A student element must have a student ID: <!ATTLIST student studentID ID #REQUIRED> ID, IDREF, IDREFS
Attributes can refer to entities “Entity” refers to substituting a reference for a text value & refers to the & character Unparsed Entity is a reference that isn’t parsed Can reuse references for long values, or hard to manage characters (i.e. tab, line feed) Entity must be declared in the DTD <!ENTITY classTitle “XML”> When classTitle found in document, replaced with XML Entities and Attributes
Can specify how the value will appear in the document Must always specify a value declaration DEFAULT sets a value for an attribute if a value isn’t provided Include default value in double quotes FIXED sets a value that must occur; if an attribute has a different value, a validation error occurs REQUIRED specifies that the attribute (and value) must exist IMPLIED means the attribute is optional Attribute Value Declarations

More Related Content

What's hot

What's hot (20)

Xml dtd
Xml dtdXml dtd
Xml dtd
 
XML and DTD
XML and DTDXML and DTD
XML and DTD
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
Dtd
DtdDtd
Dtd
 
DTD
DTDDTD
DTD
 
DTD
DTDDTD
DTD
 
4 xml namespaces and xml schema
4   xml namespaces and xml schema4   xml namespaces and xml schema
4 xml namespaces and xml schema
 
Xml Java
Xml JavaXml Java
Xml Java
 
3 xml namespaces and xml schema
3   xml namespaces and xml schema3   xml namespaces and xml schema
3 xml namespaces and xml schema
 
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
 
Document type definitions part 1
Document type definitions part 1Document type definitions part 1
Document type definitions part 1
 
XML, DTD & XSD Overview
XML, DTD & XSD OverviewXML, DTD & XSD Overview
XML, DTD & XSD Overview
 
XML Schema
XML SchemaXML Schema
XML Schema
 
Xml dtd- Document Type Definition- Web Technology
Xml dtd- Document Type Definition- Web TechnologyXml dtd- Document Type Definition- Web Technology
Xml dtd- Document Type Definition- Web Technology
 
01 xml document structure
01 xml document structure01 xml document structure
01 xml document structure
 
Basic XML
Basic XMLBasic XML
Basic XML
 
XML Introduction
XML IntroductionXML Introduction
XML Introduction
 
XML Introduction
XML IntroductionXML Introduction
XML Introduction
 
Difference between dtd and xsd
Difference between dtd and xsdDifference between dtd and xsd
Difference between dtd and xsd
 
Introduction to xml
Introduction to xmlIntroduction to xml
Introduction to xml
 

Similar to Document Type Definitions

Similar to Document Type Definitions (20)

Document type definitions part 2
Document type definitions part 2Document type definitions part 2
Document type definitions part 2
 
CIS-189 Final Review
CIS-189 Final ReviewCIS-189 Final Review
CIS-189 Final Review
 
2-DTD.ppt
2-DTD.ppt2-DTD.ppt
2-DTD.ppt
 
Well Formed XML
Well Formed XMLWell Formed XML
Well Formed XML
 
It8074 soa-unit i
It8074 soa-unit iIt8074 soa-unit i
It8074 soa-unit i
 
it8074-soa-uniti-.pdf
it8074-soa-uniti-.pdfit8074-soa-uniti-.pdf
it8074-soa-uniti-.pdf
 
Archivists' Toolkit Training-Resources, Digital Objects, and Reports
Archivists' Toolkit Training-Resources, Digital Objects, and ReportsArchivists' Toolkit Training-Resources, Digital Objects, and Reports
Archivists' Toolkit Training-Resources, Digital Objects, and Reports
 
10. XML in DBMS
10. XML in DBMS10. XML in DBMS
10. XML in DBMS
 
Xml and Co.
Xml and Co.Xml and Co.
Xml and Co.
 
Unit iv xml
Unit iv xmlUnit iv xml
Unit iv xml
 
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
 
Jungahan web presentation
Jungahan web presentationJungahan web presentation
Jungahan web presentation
 
Xml2
Xml2Xml2
Xml2
 
Xm lquickref
Xm lquickrefXm lquickref
Xm lquickref
 
Xml For Dummies Chapter 8 Understanding And Using Dt Ds it-slideshares.blog...
Xml For Dummies   Chapter 8 Understanding And Using Dt Ds it-slideshares.blog...Xml For Dummies   Chapter 8 Understanding And Using Dt Ds it-slideshares.blog...
Xml For Dummies Chapter 8 Understanding And Using Dt Ds it-slideshares.blog...
 
It8074 soa-unit i
It8074 soa-unit iIt8074 soa-unit i
It8074 soa-unit i
 
Web Technologies Unit 2 Print.pdf
Web Technologies Unit 2 Print.pdfWeb Technologies Unit 2 Print.pdf
Web Technologies Unit 2 Print.pdf
 
Encoded Archival Description (EAD)
Encoded Archival Description (EAD) Encoded Archival Description (EAD)
Encoded Archival Description (EAD)
 

More from Randy Riness @ South Puget Sound Community College

More from Randy Riness @ South Puget Sound Community College (20)

Stored procedures
Stored proceduresStored procedures
Stored procedures
 
3 sql overview
3 sql overview3 sql overview
3 sql overview
 
Normalization
NormalizationNormalization
Normalization
 
CIS160 final review
CIS160 final reviewCIS160 final review
CIS160 final review
 
SQL Constraints
SQL ConstraintsSQL Constraints
SQL Constraints
 
CIS 245 Final Review
CIS 245 Final ReviewCIS 245 Final Review
CIS 245 Final Review
 
CIS145 Final Review
CIS145 Final ReviewCIS145 Final Review
CIS145 Final Review
 
Cis166 Final Review C#
Cis166 Final Review C#Cis166 Final Review C#
Cis166 Final Review C#
 
Classes and Objects
Classes and ObjectsClasses and Objects
Classes and Objects
 
CIS245 sql
CIS245 sqlCIS245 sql
CIS245 sql
 
Cis245 Midterm Review
Cis245 Midterm ReviewCis245 Midterm Review
Cis245 Midterm Review
 
CSS
CSSCSS
CSS
 
XPath
XPathXPath
XPath
 
XSLT Overview
XSLT OverviewXSLT Overview
XSLT Overview
 
Views
ViewsViews
Views
 
CIS282 Midterm review
CIS282 Midterm reviewCIS282 Midterm review
CIS282 Midterm review
 
Schemas 2 - Restricting Values
Schemas 2 - Restricting ValuesSchemas 2 - Restricting Values
Schemas 2 - Restricting Values
 
CIS 145 test 1 review
CIS 145 test 1 reviewCIS 145 test 1 review
CIS 145 test 1 review
 
XML schemas
XML schemasXML schemas
XML schemas
 
DOM specifics
DOM specificsDOM specifics
DOM specifics
 

Recently uploaded

POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 

Recently uploaded (20)

POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 

Document Type Definitions

  • 2. DTD stands for Document Type Definition Allows an XML document to go further than meeting the requirements of being well-formed Specifies requirements to be valid A valid XML document matches definitions of allowable elements, attributes DTD Overview
  • 3. Validation can be done in code (i.e. using javascript, VB and DOM) DTD’s allow use of a validating parser that compares the document against specifications Typically makes application changes and maintenance easier Less tied to a particular programming language/environment Validation
  • 4. Declarations are used to specify document requirements Document type declaration Element declaration Attribute List declaration Entity declaration Declarations
  • 5. Includes name of root element Allows specification of where the DTD is located DTD can be embedded in the XML file (local) DTD can refer to external file, Uniform Resource Identifier (URI) Local takes precedence over external Document Type Declaration
  • 6. Element Declaration has 3 parts: Declaration Element name Element content Element content can include a list of child elements or data Element Declaration
  • 7. DTD included in XML document Definition of a student: <!DOCTYPE student[ <!ELEMENT student(first, last, studentID)> <!ELEMENT first (#PCDATA)> <!ELEMENT last(#PCDATA)> <ELEMENT studentID(#PCDATA)> ]> LocalDTD Document Type Declaration Element Declaration A student element is made up of first name, last name, and student id elements
  • 8. DTD exists in external file/location Must use keyword to specify type of location SYSTEM is a reference to local file system PUBLIC is reference to DTD accessed through a catalog Can use both together If can’t find catalog reference can use specified file External Definition
  • 9. Reference in XML file: <!DOCTYPE student SYSTEM “student.dtd”> External file: <!ELEMENT student(first, last, studentID)> <!ELEMENT first (#PCDATA)> <!ELEMENT last(#PCDATA)> <ELEMENT studentID(#PCDATA)> ]> Sample External Definition Document Type Declaration Element Declaration
  • 10. Element name must match name in XML document If using namespaces, prefixes must match Content Model defines what the element can store An element Mixed (i.e. data and element) Empty Any Working With Elements
  • 11. One element can contain another Can specify the elements contained by sequence Can specify the elements contained as a choice Element Content
  • 12. Error raised if an element is missing Error raised if there are extra elements Error raised if elements in a different order For a student, our content must be in firstname, lastname, studentID order If find an element “major”, error If order varies, error If missing first, last, or studentID, error Content by Sequence
  • 13. Can allow content to vary between elements | (vertical bar or pipe) indicates OR If add a Grade element to a student that can be a letter or percent: <!ELEMENT grade (letter | percent)> <!ELEMENT letter (#PCDATA)> <!ELEMENT percent (#PCDATA) Indicates that must have letter or percent element Content by Choice
  • 14. A name may be a full name (first, middle, last) or just first and last: <!ELEMENT name (fullName | (first, last))> <!ELEMENT fullName (first, middle, last)> <!ELEMENT first (#PCDATA)> <!ELEMENT middle (#PCDATA)> <!ELEMENT last (#PCDATA)> By Choice: Example
  • 15. Allows combination of elements and parsed character data Can include additional information within an element, eg. how to display Rules: Managed by using Choice (or) PCDATA must appear first in list of elements List cannot include inner content model (only simple elements) If there are child elements, include * * Indicates that may appear zero or more times Mixed Content
  • 16. If want to include emphasis with the letter grade Data: <letter><em>4</em></letter> Declaration: <!ELEMENT letter (#PCDATA | em)*> Describes a letter element as the content (pcdata) plus emphasis element Mixed Content -2
  • 17. An element can be empty <br /> (never has child, content) Declaration includes EMPTY: <!ELEMENT br EMPTY> Means that the element CANNOT contain content Empty Content
  • 18. An element can contain any kind of value (or be empty) Any elements declared in the DTD can occur, any number of times Only elements that are part of the DTD can be part of the document! May be empty May contain PCDATA Least restrictive model Any Content
  • 19. How many times can an element occur? How many times must an element occur? Cardinality
  • 20. A student must have a first name A student may or may not have a last name A student may have one or more majors, or none (undeclared) <!ELEMENT student (first, last?, major*)> Note: Cardinality indicator doesn’t affect the element declaration (i.e. major) Cardinality: Example
  • 21. Elements tend to be used to describe a logical unit of information Attributes are typically used to store data about characteristics (properties) May have a Movie element with attributes for Title, Rental Price, Rental Days No specific rules about how to use elements and attributes Attributes and DTD’s
  • 22. Attributes allow more limits on data Can have a list of acceptable values Can have a default value Some ability to specify a data type Concise, about a single name/value pair Attributes have limits Can’t store long strings of text Can’t nest values Whitespace can’t be ignored Attributes and Elements
  • 23. Declaration: <!ATTLISTElementNameAttrNameAttrType Default> Specify the Element the attribute belongs to Specify the Name of the attribute Specify the Type of data the attribute stores Specify characteristics of the values (Default or attribute value) List either the default value or other characteristic of value – required, optional Specifying Attributes
  • 24. CDATA – unparsed character data Enumerated – series/list of string values Entity/Entities – reference entity definition(s) ID – unique identifier for the element IDREF – refer to the ID of another element IDREFS – list of ID’s of other elements separated by whitespace NMTOKEN/NMTOKENS – value(s) of attribute can be anything that follows rules for XML name Sample Attribute Data Types
  • 25. Specifies that attribute value must be found in a particular list Each value in list must be valid XML name Limits on spaces, characters Use | (pipe) to separate members of list If specifying list letter grades for a student: <!ATTLIST student grade (A | B | C | D | F | V | W | I) #IMPLIED> Enumerated Attributes Element Attribute Enumerated List
  • 26. An ID specifies that the element must have a unique value within the document Allows reliable way to refer to a specific element No spaces allowed in value Typically replace space with underscore Attribute list can include only one ID IDREF, IDREFS allows an element to be associated with another or multiple other elements A student element must have a student ID: <!ATTLIST student studentID ID #REQUIRED> ID, IDREF, IDREFS
  • 27. Attributes can refer to entities “Entity” refers to substituting a reference for a text value & refers to the & character Unparsed Entity is a reference that isn’t parsed Can reuse references for long values, or hard to manage characters (i.e. tab, line feed) Entity must be declared in the DTD <!ENTITY classTitle “XML”> When classTitle found in document, replaced with XML Entities and Attributes
  • 28. Can specify how the value will appear in the document Must always specify a value declaration DEFAULT sets a value for an attribute if a value isn’t provided Include default value in double quotes FIXED sets a value that must occur; if an attribute has a different value, a validation error occurs REQUIRED specifies that the attribute (and value) must exist IMPLIED means the attribute is optional Attribute Value Declarations