Session III Chapter 6 – Creating DTDs

Slides:



Advertisements
Similar presentations
XML I.
Advertisements

Defining XML The Document Type Definition. Document Type Definition text syntax for defining –elements of XML –attributes (and possibly default values)
XML 6.3 DTD 6. XML and DTDs A DTD (Document Type Definition) describes the structure of one or more XML documents. Specifically, a DTD describes:  Elements.
XML Document Type Definitions ( DTD ). 1.Introduction to DTD An XML document may have an optional DTD, which defines the document’s grammar. Since the.
Document Type Definition DTDs CS-328. 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 Type Definitions
More of DTDs Lecture 3. Symbols used in DTD COMMA “, ” enforces sequence.
A Technical Introduction to XML Transparency No. 1 XML quick References.
 2002 Prentice Hall, Inc. All rights reserved. ISQA 407 XML/WML Winter 2002 Dr. Sergio Davalos.
Full declaration When an element is declared to have element content, the children element types must also be declared Example: to which the following.
Tutorial 11 Creating XML Document
Document Type Definitions. XML and DTDs A DTD (Document Type Definition) describes the structure of one or more XML documents. Specifically, a DTD describes:
VALIDATING AN XML DOCUMENT
Introduction to XML This material is based heavily on the tutorial by the same name at
Copyright © 2003 Pearson Education, Inc. Slide 2-1 Created by Cheryl M. Hughes, Harvard University Extension School — Cambridge, MA The Web Wizard’s Guide.
XML Validation I DTDs Robin Burke ECT 360 Winter 2004.
XP New Perspectives on XML Tutorial 3 1 DTD Tutorial – Carey ISBN
Validating DOCUMENTS with DTDs
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation Document Type Definition.
Copyright © 2003 Pearson Education, Inc. Slide 3-1 Created by Cheryl M. Hughes, Harvard University Extension School — Cambridge, MA The Web Wizard’s Guide.
Session III Chapter 7 – Entities and Notation in DTD’s
Introduction to XML cs3505. References –I got most of this presentation from this site –O’reilly tutorials.
Chapter 4: Document Type Definitions. Chapter 4 Objectives Learn to create DTDs Validate an XML document against a DTD Use DTDs to create XML documents.
XML CPSC 315 – Programming Studio Fall 2008 Project 3, Lecture 1.
XML Language Family Detailed Examples Most information contained in these slide comes from: These slides are intended.
Document Type Definitions Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
XML 1 Enterprise Applications CE00465-M XML. 2 Enterprise Applications CE00465-M XML Overview Extensible Mark-up Language (XML) is a meta-language that.
August Chapter 2 - Markup and Core Concepts Learning XML by Erik T. Ray Slides were developed by Jack Davis College of Information Science and Technology.
XML Syntax - Writing XML and Designing DTD's
XP 1 DECLARING A DTD A DTD can be used to: –Ensure all required elements are present in the document –Prevent undefined elements from being used –Enforce.
Session IV Chapter 9 – XML Schemas
1 Tutorial 13 Validating Documents with DTDs Working with Document Type Definitions.
Avoid using attributes? Some of the problems using attributes: Attributes cannot contain multiple values (child elements can) Attributes are not easily.
 2002 Prentice Hall, Inc. All rights reserved. Chapter 6 – Document Type Definition (DTD) Outline 6.1Introduction 6.2Parsers, Well-formed and Valid XML.
XML 2nd EDITION Tutorial 1 Creating An Xml Document.
XML - DTD Week 4 Anthony Borquez. What can XML do? provides an application independent way of sharing data. independent groups of people can agree to.
CIS 451: XML DTDs Dr. Ralph D. Westfall February, 2009.
IS432: Semi-Structured Data Dr. Azeddine Chikh. 4. Document Type Definitions (DTDs)
IS432 Semi-Structured Data Lecture 2: DTD Dr. Gamal Al-Shorbagy.
XML Validation I DTDs Robin Burke ECT 360 Winter 2004.
XML Instructor: Charles Moen CSCI/CINF XML  Extensible Markup Language  A set of rules that allow you to create your own markup language  Designed.
XP 1 Creating an XML Document Developing an XML Document for the Jazz Warehouse XML Tutorial.
Lecture 16 Introduction to XML Boriana Koleva Room: C54
An Introduction to XML Sandeep Bhattaram
XML Introduction. What is XML? XML stands for eXtensible Markup Language XML stands for eXtensible Markup Language XML is a markup language much like.
1/11 ITApplications XML Module Session 3: Document Type Definition (DTD) Part 1.
The eXtensible Markup Language (XML). Presentation Outline Part 1: The basics of creating an XML document Part 2: Developing constraints for a well formed.
CSE3201 Information Retrieval Systems DTD Document Type Definition.
XML Design Goals 1.XML must be easily usable over the Internet 2.XML must support a wide variety of applications 3.XML must be compatible with SGML 4.It.
Document Type Definitions (DTD) A Document Type Definition (DTD) defines the structure and the legal elements and attributes of an XML document. A DTD.
1 Tutorial 14 Validating Documents with Schemas Exploring the XML Schema Vocabulary.
Beginning XML 3 rd Edition. Chapter 4: Document Type Definitions.
INFSY 547: WEB-Based Technologies Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
SNU OOPSLA Lab. Logical structure © copyright 2001 SNU OOPSLA Lab.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2.
225 City Avenue, Suite 106 Bala Cynwyd, PA , phone , fax presents… XML Syntax v2.0.
Well Formed XML The basics. A Simple XML Document Smith Alice.
XML CSC1310 Fall HTML (TIM BERNERS-LEE) HyperText Markup Language  HTML (HyperText Markup Language): December  Markup  Markup is a symbol.
1 Internal DTD External DTD. 2 Internal DTD ]> Tove Jani Reminder Don't forget me this weekend.
Document Type Definition (DTD) Eugenia Fernandez IUPUI.
DTD Document Type Definition. Agenda Introduction to DTD DTD Building Blocks DTD Elements DTD Attributes DTD Entities DTD Exercises DTD Q&A.
Copyrighted material John Tullis 3/18/2016 page 1 04/29/00 XML Part 4 John Tullis DePaul Instructor
CH 9 Attribute Declaration 1. Objective What is an attribute Declaring attributes Declaring multiple attribute Alternatives to default attributes values.
CITA 330 Section 2 DTD. Defining XML Dialects “Well-formedness” is the minimal requirement for an XML document; all XML parsers can check it Any useful.
Extensible Markup Language (XML) Pat Morin COMP 2405.
Document Type Definition DTDs
New Perspectives on XML
Session II Chapter 6 – Creating DTDs
Document Type Definition (DTD)
XML IST 421.
Presentation transcript:

Session III Chapter 6 – Creating DTDs http://www.profburnett.com CMP 051 XML Introduction Session III Chapter 6 – Creating DTDs http://www.profburnett.com

Outline Introduction DTD Declaration Syntax DTD XML Building Blocks The Need for DTDs DTD Features DTD Schematic DTD Declaration Syntax DTD XML Building Blocks DTD Elements DTD Attributes 8/1/2014 Copyright © Carl M. Burnett

Introduction Creates rules and structures for XML vocabulary Document Type Definitions (DTDs) and XML schemas are vehicles for document modeling 11/9/2018 Copyright © Carl M. Burnett

The Need for DTDs Default attribute values Handling of white space Part of the declaration (DTD or schema portion) must be processed To obtain correct default values Handling of white space Without the DTD, there is no way for the processor to distinguish between element content and mixed content 11/9/2018 Copyright © Carl M. Burnett

The Need for DTDs Authoring environments Authoring methods Process the document type declarations for authors To comply with the content models of the document Authoring methods DTD is required for any structure to be created, understood, and maintained 11/9/2018 Copyright © Carl M. Burnett

DTD Features Declares a set of allowed elements DTD forms the vocabulary of the language Defines the content model for each element Content model indicates What elements can be nested within other elements The order in which elements appear How many elements are allowed 11/9/2018 Copyright © Carl M. Burnett

DTD Features Declares a set of allowed attributes for each of its elements Attributes defines the name, datatype, default values and behavior Includes other mechanisms Entity declarations Notation declarations 11/9/2018 Copyright © Carl M. Burnett

Document Type Definition Basic DTD Schematic Document Type Definition Prolog (optional) Element Declarations Attribute List Declarations Entity Declarations Notation Declarations Other Content 11/9/2018 Copyright © Carl M. Burnett

DTD Declaration Syntax Declaration Identifier <!ELEMENT elementname content-model> Start Indicator End Indicator Reserved Keyword (Upper Case Only) 11/9/2018 Copyright © Carl M. Burnett

DTD - XML Building Blocks All XML documents and HTML documents) have the following building blocks: Elements Attributes Entities PCDATA CDATA 8/1/2014 Copyright © Carl M. Burnett

DTD Elements Element type declarations Specify the names of elements and nature of their content Define only one element DTD must contain as many element declarations as there are elements 11/9/2018 Copyright © Carl M. Burnett

Element declaration syntax Valid XML Name (begins with a letter, colon, or underscore) <!ELEMENT elementname content-model> Start Indicator Content Model (also called content Specification) End Indicator Reserved Keyword (Upper Case Only) 11/9/2018 Copyright © Carl M. Burnett

XML Naming Conventions Element names Can start with a letter, a colon, or an underscore (no numbers) Rest of the name can be alphanumeric, underscores, hyphens, colons and periods Can not contain reserved characters: ampersand (&), at symbol (@), or less than symbol (<) Can not contain white space or use parentheses (), or brackets [] 11/9/2018 Copyright © Carl M. Burnett

Elements with Text - Parsed Character Data only (PCDATA) Many Elements will only contain text. Use reserved keyword/symbol combination #PCDATA Parser checks the entity references Replaces the reference with actual entity values. <ELEMENT name (#PCDATA)> <!ELEMENT location (#PCDATA)> <!ELEMENT height (#PCDATA)> <!ELEMENT year_built (#PCDATA)> <!ELEMENT year_destroyed (#PCDATA)> <!ELEMENT how_destroyed (#PCDATA)> <!ELEMENT story (#PCDATA)> 1. Type <!ELEMENT TAG to DEFEINE tag. 2. Type (#PCDATA) to define the tag that contains a text value. 3. Type > to close out the Element definition. 11/9/2018 Copyright © Carl M. Burnett

Element with Empty Element 1. Type <!ELEMENT TAG to DEFEINE tag. 2. Type EMPTY to define the tag that contains an empty value. <!ELEMENT main_image EMPTY> <!ELEMENT source EMPTY> <!ELEMENT name (#PCDATA)> <!ELEMENT location (#PCDATA)> <!ELEMENT height (#PCDATA)> <!ELEMENT year_built (#PCDATA)> <!ELEMENT year_destroyed (#PCDATA)> <!ELEMENT how_destroyed (#PCDATA)> <!ELEMENT story (#PCDATA)> 3. Type > to close out the Element definition. 11/9/2018 Copyright © Carl M. Burnett

Element that Contain Children Elements Elements can be parent elements with child elements. <!ELEMENT wonder (name, location, height)> <!ELEMENT name (#PCDATA)> <!ELEMENT location (#PCDATA)> <!ELEMENT height (#PCDATA)> 1. Type <!ELEMENT TAG to DEFEINE tag. 2. Type (child1, child2)to define the children elements. 3. Type > to close out the Element definition. Then define the Children elements. 11/9/2018 Copyright © Carl M. Burnett

Elements with Choices Contain both data and child elements #PCDATA must be specified within the parentheses (declares the element may contain parseable data) Separate child elements with vertical line (| known as the pipe) <!ELEMENT ancient_wonders (wonder+)> <!ELEMENT wonder (#PCDATA | name | location | city | country)*> <!ELEMENT name (#PCDATA)> <!ELEMENT location (#PCDATA)> <!ELEMENT city (#PCDATA)> <!ELEMENT country (#PCDATA)> 1. Type <!ELEMENT TAG to DEFEINE tag. * Is a qualifier to allow elements to have a number of choices. 2. Type (#PCDATA | child1 | child2 | child3) to define the children elements. 3. Type > to close out the Element definition. Then define the Children elements. 11/9/2018 Copyright © Carl M. Burnett

Elements with No Content Restrictions Elements with any content must use reserved keyword ANY. XML validator does not have to perform a check on the specified element’s content. <!ELEMENT ancient_wonders (wonder+)> <!ELEMENT wonder (#PCDATA | name | location | city | country)*> <!ELEMENT name (#PCDATA)> <!ELEMENT location ANY> <!ELEMENT city (#PCDATA)> <!ELEMENT country (#PCDATA)> 1. Type <!ELEMENT TAG to DEFEINE tag. 2. Type ANY to define the type of element. 3. Type > to close out the Element definition. 11/9/2018 Copyright © Carl M. Burnett

Operators Used with Element Content Comma (,) specifies a required sequence of child elements Vertical line, or “pipe”, ( | ) specifies a list of candidate child elements Question mark (?) specifies that the child element is optional Plus Sign (+) specifies that at least one child element(s) is required Asterisk (*) specifies that zero or more of the child element(s) may appear 11/9/2018 Copyright © Carl M. Burnett

DTD Attributes In a DTD, attributes are declared with an ATTLIST declaration. In XML, there are no rules about when to use attributes, and when to use child elements. Avoid using attributes? 8/1/2014 Copyright © Carl M. Burnett

Avoid Using Attributes? Some of the problems with attributes are: attributes cannot contain multiple values (child elements can) attributes are not easily expandable (for future changes) attributes cannot describe structures (child elements can) attributes are more difficult to manipulate by program code attribute values are not easy to test against a DTD If you use attributes as containers for data, you end up with documents that are difficult to read and maintain. Try to use elements to describe data. Use attributes only to provide information that is not relevant to the data. 8/1/2014 Copyright © Carl M. Burnett

An Exception to Attribute Rule Sometimes you can assign ID references to elements. These ID references can be used to access XML elements in much the same way as the NAME or ID attributes in HTML. 8/1/2014 Copyright © Carl M. Burnett

Defining Attributes Attribute Definition consist of four parts: Elements Name Attribute Name Attribute Type Optional Status <!ELEMENT height (#PCDATA)> <!ATTLIST height units CDATA #REQUIRED> 1. Type <!ATTLIST tag where the tag is element name. 2. Type att_name where att_name is name of the attribute. 3. Type CDATA wto indicate the attribute type is text. 4. Type #IMPLIED or #REQUIRED for the optional status. The #IMPLIED can be omitted if desired. 5. Type > to close out the attribute definition. 8/1/2014 Copyright © Carl M. Burnett

Defining Attribute Default Values <!ELEMENT height (#PCDATA)> <!ATTLIST height units CDATA “Default_Value”> You cannot combine the use of optional status of #IMPLIED or #REQUIRED if you provide a default value for the attribute. 8/1/2014 Copyright © Carl M. Burnett

Defining Attribute with Choices 1. Type <!ATTLIST tag where the tag is element name. <!ELEMENT height (#PCDATA)> <!ATTLIST height units (inches|feet) #REQUIRED> 2. Type att_name where att_name is name of the attribute. 3. Type (choice1 | choice2) where choice represents the possible value for the attribute choice. 4. Type #IMPLIED or #REQUIRED for the optional status. The #IMPLIED can be omitted if desired. 5. Type > to close out the attribute definition. 8/1/2014 Copyright © Carl M. Burnett

Defining Attributes with Unique Values 1. Type <!ATTLIST tag where the tag is element name. <!ELEMENT wonder (name)> <!ATTLIST wonder code ID #REQUIRED> 2. Type att_name where att_name is name of the attribute. 3. Type ID to define value of the attribute. 4. Type #IMPLIED or #REQUIRED for the optional status. The #IMPLIED can be omitted if desired. 8/1/2014 Copyright © Carl M. Burnett

Referencing Attributes with Unique Values 1. Type <!ATTLIST tag where the tag is element name. <!ELEMENT special_site (title, url)> <!ATTLIST special_site wonder_focus IDREF #REQUIRED> 2. Type att_name where att_name is name of the attribute. 3. Type IDREF hto define attribute that contains a value matching an existing ID value. 4. You can also type IDREFS that can contains several values separated with white spaces. <!ELEMENT general_site (title, url)> <!ATTLIST general_site contents IDREFS #REQUIRED> 5. Type #IMPLIED or #REQUIRED for the optional status. The #IMPLIED can be omitted if desired. 8/1/2014 Copyright © Carl M. Burnett

Restricting Attributes to Valid XML Names 1. Type <!ATTLIST tag where the tag is element name. <wonder> <w_visit primary_keyword="colossus"/> <name language="English"> Colossus of Rhodes</name> . . . primary_keyword="great pyramid"/> Great Pyramid of Giza</name> 2. Type att_name where att_name is name of the attribute. 3. Type NMTOKEN if you want the attribute value to be a valid XML name. 4. You can also type NMTOKENS if you want the attribute value to be a valid XML name based on a separated liste with white spaces. 5. Type #IMPLIED or #REQUIRED for the optional status. The #IMPLIED can be omitted if desired. 8/1/2014 Copyright © Carl M. Burnett

Chapter 7 - Entities and Notations in DTDs Review Introduction The Need for DTDs DTD Features DTD Schematic DTD Declaration Syntax DTD XML Building Blocks DTD Elements DTD Attributes Next: Chapter 7 - Entities and Notations in DTDs 8/1/2014 Copyright © Carl M. Burnett