 2002 Prentice Hall, Inc. All rights reserved. ISQA 407 XML/WML Winter 2002 Dr. Sergio Davalos.

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.
Introduction to XML: DTD
XML Study-Session: Part II Validating XML Documents.
XML Language Family Detailed Examples Most information contained in these slide comes from: These slides are intended.
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
XML Schemas Microsoft XML Schemas W3C XML Schemas.
Introduction to XLink Transparency No. 1 XML Information Set W3C Recommendation 24 October 2001 (1stEdition) 4 February 2004 (2ndEdition) Cheng-Chia Chen.
A Technical Introduction to XML Transparency No. 1 XML quick References.
Week 4 Document Type Definition (DTD)
Full declaration When an element is declared to have element content, the children element types must also be declared Example: to which the following.
Physical and Logical Structure
More xml chpt 6 DTD Document Type Definition. DTD: document type definition A DTD is defined using EBNF (extended BNF) and can be used to specify allowable.
1 Print your own copy If you bring it along, hand in with your exam script Do not write anything extra or you will be penalized Student Name: Student Number:
XML Verification Well-formed XML document  conforms to basic XML syntax  contains only built-in character entities Validated XML document  conforms.
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
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Creating Document Type Definitions (DTDs) Ellen Pearlman Eileen Mullin.
XML Validation I DTDs Robin Burke ECT 360 Winter 2004.
Tutorial 3: XML Creating a Valid XML Document. 2 Creating a Valid Document You validate documents to make certain necessary elements are never omitted.
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.
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.
 2002 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 – Schemas Outline 7.1Introduction 7.2Schemas vs. DTDs 7.3Microsoft XML Schema: Describing Elements.
Introduction to XML. What is XML? Extensible Markup Language XML Easier-to-use subset of SGML (Standard Generalized Markup Language) XML is a.
XML 1 Enterprise Applications CE00465-M XML. 2 Enterprise Applications CE00465-M XML Overview Extensible Mark-up Language (XML) is a meta-language that.
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.
XML (2) DTD Sungchul Hong.
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.
Lecture 6 XML DTD Content of.xml fileContent of.dtd file.
1 Chapter 10: XML What is XML What is XML Basic Components of XML Basic Components of XML XPath XPath XQuery XQuery.
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.
SNU OOPSLA Lab. XML Documents 1 : Structure The ubiquitous XML(2) © copyright 2001 SNU OOPSLA Lab.
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.
Lecture 16 Introduction to XML Boriana Koleva Room: C54
2 XML Syntax XML Document Structure August 15, :00 Darmstadt Hessen Germany fine 25 SW 6 Markup Content.
An Introduction to XML Sandeep Bhattaram
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Understanding How XML Works Ellen Pearlman Eileen Mullin Programming the.
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 Dr Alexiei Dingli XML Technologies DTD. 2 Document Type Definition Defines –the legal building blocks of an XML document –the document structure –The.
1/11 ITApplications XML Module Session 3: Document Type Definition (DTD) Part 1.
CSE3201 Information Retrieval Systems DTD Document Type Definition.
Sheet 1XML Technology in E-Commerce 2001Lecture 2 XML Technology in E-Commerce Lecture 2 Logical and Physical Structure, Validity, DTD, XML Schema.
Document Type Definitions (DTD) A Document Type Definition (DTD) defines the structure and the legal elements and attributes of an XML document. A DTD.
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.
1 Internal DTD External DTD. 2 Internal DTD ]> Tove Jani Reminder Don't forget me this weekend.
XML DTD. XML Validation XML with correct syntax is "Well Formed" XML. XML validated against a DTD is "Valid" XML.
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.
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.
Session III Chapter 6 – Creating DTDs
New Perspectives on XML
Session II Chapter 6 – Creating DTDs
Presentation transcript:

 2002 Prentice Hall, Inc. All rights reserved. ISQA 407 XML/WML Winter 2002 Dr. Sergio Davalos

 2002 Prentice Hall, Inc. All rights reserved. Chapter 6 – Document Type Definition (DTD) Outline 6.1Introduction 6.2Parsers, Well-formed and Valid XML Documents 6.3Document Type Declaration 6.4Element Type Declarations 6.4.1Sequences, Pipe Characters and Occurrence Indicators EMPTY, Mixed Content and ANY 6.5Attribute Declarations 6.5.1Attribute Defaults ( #REQUIRED, #IMPLIED, #FIXED ) 6.6Attribute Types 6.6.1Tokenized Attribute Type ( ID, IDREF, ENTITY, NMTOKEN ) 6.6.2Enumerated Attribute Types 6.7Conditional Sections 6.8Whitespace Characters 6.9Case Study: Writing a DTD for the Day Planner Application

 2002 Prentice Hall, Inc. All rights reserved. 6.1 Introduction Document Type Definitions (DTDs) –Define structure of XML document i.e., what elements, attributes, etc. are permitted in document –XML document not required to have DTD Usually recommended for document conformity –Use Extended Backus-Naur Form (EBNF) grammar

 2002 Prentice Hall, Inc. All rights reserved. 6.2 Parsers, Well-formed and Valid XML Documents Parsers –Validating Able to read DTD Determine whether XML document conforms to DTD –Valid document conforms to DTD »Document is then well formed, by definition »Documents can be well formed, but not valid –Nonvalidating Able to read DTD Cannot check document against DTD for conformity

 2002 Prentice Hall, Inc. All rights reserved. 6.3 Document Type Declaration Document Type Declaration –Introduce DTDs into XML documents –Placed in XML document’s prolog –Begins with <!DOCTYPE –Ends with > –Can point to External subsets –Declarations outside document –Exist in different file »typically ending with.dtd extension Internal subsets –Declarations inside document –Visible only within document in which it resides

 2002 Prentice Hall, Inc. All rights reserved. 6.4 Element Type Declarations Element type declarations –Declare elements in XML documents –Begin with <!ELEMENT –End with > myElement is generic identifier Parentheses specify element’s content (content specification) Keyword PCDATA –Element must contain parsable character data »All text treated as markup

 2002 Prentice Hall, Inc. All rights reserved. Outline u Fig. 6.1XML document declaring its associated DTD. DOCTYPE starts document type declaration Document type declaration is named myMessage Keyword SYSTEM specifies external subset intro.dtd is DTD Welcome to XML! 10 Document type declaration is named myMessage Keyword SYSTEM specifies external subset DOCTYPE starts document type declaration intro.dtd is DTD

 2002 Prentice Hall, Inc. All rights reserved. Outline Fig. 6.2Validation with using an external DTD. Declare element myMessage Element myMessage contains child element message Declare element message Element message contains parsable character data Declare element myMessage Element myMessage contains child element message Declare element message Element message contains parsable character data

 2002 Prentice Hall, Inc. All rights reserved. Fig. 6.2 Validation with using an external DTD.

 2002 Prentice Hall, Inc. All rights reserved. Fig. 6.2 Validation with using an external DTD (cont.)

 2002 Prentice Hall, Inc. All rights reserved. Outline Fig. 6.3Non-valid XML document. Element myMessage ’s structure does not adhere to that specified in intro.dtd Element myMessage ’s structure does not adhere to that specified in intro.dtd

 2002 Prentice Hall, Inc. All rights reserved. Fig. 6.3 Non-valid XML document.

 2002 Prentice Hall, Inc. All rights reserved Sequences, Pipe Characters and Occurrence Indicators Sequences –Specify order in which elements occur –Comma (, ) used as delimiter

 2002 Prentice Hall, Inc. All rights reserved Sequences, Pipe Characters and Occurrence Indicators (cont.) Pipe characters ( | ) –Specify choices

 2002 Prentice Hall, Inc. All rights reserved Sequences, Pipe Characters and Occurrence Indicators (cont.) Occurrence indicators –Specify element’s frequency –Plus sign ( + ) indicates one or more occurrences –Asterisk ( * ) indicates optional element –Question mark ( ? ) indicates element can occur only once

 2002 Prentice Hall, Inc. All rights reserved. Fig. 6.4 Occurrence indicators.

 2002 Prentice Hall, Inc. All rights reserved EMPTY, Mixed Content and ANY Content specification types –EMPTY Elements do not contain character data Elements do not contain child elements Markup for oven element

 2002 Prentice Hall, Inc. All rights reserved EMPTY, Mixed Content and ANY Content specification types –Mixed content Combination of elements and PCDATA Markup for myMessage Here is some text, some other text and even more text

 2002 Prentice Hall, Inc. All rights reserved. Outline Fig. 6.5Example of a mixed-content element. Specify DTD as internal subset Declare format as mixed content element Elements bold and italic have PCDATA only for content specification Element format adheres to structure in DTD <!DOCTYPE format [ ]> This is a simple formatted sentence. 14 I have tried bold. 15 I have tried italic. 16 Now what? 17 Specify DTD as internal subset Declare format as mixed content element Elements bold and italic have PCDATA only for content specification Element format adheres to structure in DTD

 2002 Prentice Hall, Inc. All rights reserved. Fig. 6.5 Example of a mixed-content element.

 2002 Prentice Hall, Inc. All rights reserved. Fig. 6.6 Illegal mixed-content element syntax.

 2002 Prentice Hall, Inc. All rights reserved EMPTY, Mixed Content and ANY Content specification types –ANY Can contain any content –PCDATA, elements or combination –Can also be empty elements Commonly used in early DTD-development stages –Replace with specific content as DTD evolves

 2002 Prentice Hall, Inc. All rights reserved. 6.5 Attribute Declarations Attribute declaration –Specifies element’s attribute list –Uses ATTLIST attribute list declaration

 2002 Prentice Hall, Inc. All rights reserved. Outline Fig. 6.7Declaring attributes. Specify DTD as internal subset Declare element myMessage with child element message Declare that attribute id contain required CDATA <!DOCTYPE myMessage [ ]> Welcome to XML! Specify DTD as internal subset Declare element myMessage with child element message Declare that attribute id contain required CDATA

 2002 Prentice Hall, Inc. All rights reserved. Fig. 6.7 Declaring attributes.

 2002 Prentice Hall, Inc. All rights reserved Attributes Defaults (#REQUIRED, #IMPLIED, #FIXED ) Attribute defaults –Specify attribute’s default value –#IMPLIED Use (application’s) default value if attribute value not specified –#REQUIRED Attribute must appear in element Document is not valid if attribute is missing –#FIXED Attribute value is constant Attribute value cannot differ in XML document

 2002 Prentice Hall, Inc. All rights reserved. 6.6 Attribute Types Attribute types –Strings ( CDATA ) No constraints on attribute values –Except for disallowing, &, ’ and ” characters –Tokenized attributes Constraints on permissible characters for attribute values –Enumerated attributes Most restrictive Take only one value listed in attribute declaration

 2002 Prentice Hall, Inc. All rights reserved Tokenized Attribute Type ( ID, IDREF, ENTITY, NMTOKEN ) Tokenized attribute types –Restrict attribute values –ID Uniquely identifies an element –IDREF Points to elements with ID attribute

 2002 Prentice Hall, Inc. All rights reserved. Outline Fig. 6.8XML document with ID and IDREF attribute types. Each shipping element has a unique identifier ( shipID ) Attribute shippedBy points to shipping element by matching shipID attribute <!DOCTYPE bookstore [ ]> to 4 days Each shipping element has a unique identifier ( shipID ) Attribute shippedBy points to shipping element by matching shipID attribute

 2002 Prentice Hall, Inc. All rights reserved. Outline Fig. 6.8XML document with ID and IDREF attribute types. (Part 2) Declare book elements with attribute shippedBy day Java How to Program 3rd edition C How to Program 3rd edition C++ How to Program 3rd edition Declare book elements with attribute shippedBy

 2002 Prentice Hall, Inc. All rights reserved. Fig. 6.7 XML document with ID and IDREF attribute types.

 2002 Prentice Hall, Inc. All rights reserved. Fig. 6.9 Error displayed by XML Validator when an invalid ID is referenced. Assign shippedBy (line 28) value “ s3 ” Outline Assign shippedBy (line 28) value “ s3 ”

 2002 Prentice Hall, Inc. All rights reserved Tokenized Attribute Type ( ID, IDREF, ENTITY, NMTOKEN ) (cont.) ENTITY tokenized attribute type –Indicate that attribute has entity for its value –Entity declaration –Entity may be used as follows: &digits; –Entity reference &digits; replaced by its value

 2002 Prentice Hall, Inc. All rights reserved. Outline Declare entity city that refers to external document elements tour.html Fig. 6.10XML document that contains an ENTITY attribute type. Declare entity city that refers to external document elements tour.html NDATA indicates that external-entity content is not XML Attribute tour for element company requires ENTITY attribute type <!DOCTYPE database [ ]> Deitel & Associates, Inc Declare entity city that refers to external document elements tour.html NDATA indicates that external- entity content is not XML Attribute tour for element company requires ENTITY attribute type

 2002 Prentice Hall, Inc. All rights reserved. Fig XML document that contains an ENTITY attribute type.

 2002 Prentice Hall, Inc. All rights reserved. Fig Error generated by XML Validator when a DTD contains a reference to an undefined entity. Replace line 16 with Outline Replace line 16

 2002 Prentice Hall, Inc. All rights reserved Tokenized Attribute Type ( ID, IDREF, ENTITY, NMTOKEN ) (cont.) NMTOKEN tokenized attribute type –“Name token” –Value consists of letters, digits, periods, underscores, hyphens and colon characters

 2002 Prentice Hall, Inc. All rights reserved Enumerated Attribute Types Enumerated attribute types –Declare list of possible values for attribute Attribute gender can have either value M or F F is default value

 2002 Prentice Hall, Inc. All rights reserved. 6.7 Conditional Sections Conditional sections –Include declarations Keyword INCLUDE –Exclude declarations Keyword IGNORE –Often used with entities Parameter entities –Preceded by percent character ( % ) –Creates entities specific to DTD –Can be used only inside DTD in which they are declared

 2002 Prentice Hall, Inc. All rights reserved. Outline Entities accept and reject represent strings INCLUDE and IGNORE, respectivelyEntities accept and reject represent strings INCLUDE and IGNORE, respectively Fig. 6.12Conditional sections in a DTD. Entities accept and reject represent strings INCLUDE and IGNORE, respectively Include this element message declaration Exclude this element message declaration <![ %accept; [ 8 9]]> 10 11<![ %reject; [ 12 13]]> Entities accept and reject represent strings INCLUDE and IGNORE, respectively Include this element message declaration Exclude this element message declaration

 2002 Prentice Hall, Inc. All rights reserved. Outline Fig. 6.13XML document that conforms to conditional.dtd Chairman 11

 2002 Prentice Hall, Inc. All rights reserved. Fig XML document that conforms to conditional.dtd.

 2002 Prentice Hall, Inc. All rights reserved. Whitespace Characters Whitespace –Either preserved or normalized Depending on context in which it is used

 2002 Prentice Hall, Inc. All rights reserved. Outline Fig. 6.14Processing whitespace in an XML document. Attribute hasCDATA requires CDATA, which preserves whitespace Other attributes normalize (do not preserve) whitespace <!DOCTYPE whitespace [ 7 <!ELEMENT whitespace ( hasCDATA, 8 hasID, hasNMTOKEN, hasEnumeration, hasMixed )> <!ATTLIST hasEnumeration enumeration ( true | false ) 21 #REQUIRED> ]> 25 Attribute hasCDATA requires CDATA, which preserves whitespace Other attributes normalize (do not preserve) whitespace

 2002 Prentice Hall, Inc. All rights reserved. Outline Fig. 6.14Processing whitespace in an XML document. (Part 2) Whitespace preserved Whitespace normalized This is text This is some additional text Whitespace preservedWhitespace normalized

 2002 Prentice Hall, Inc. All rights reserved. Outline Output from Fig Whitespace preserved Whitespace normalized >java Tree yes whitespace.xml URL: file:C:/Examplesps/Files/deleted/ch09/Tree/whitespace.xml [ document root ] +-[ element : whitespace ] +-[ ignorable ] +-[ ignorable ] +-[ ignorable ] +-[ element : hasCDATA ] +-[ attribute : cdata ] " simple cdata “ +-[ ignorable ] +-[ ignorable ] +-[ ignorable ] +-[ element : hasID ] +-[ attribute : id ] "i20“ +-[ ignorable ] +-[ ignorable ] +-[ ignorable ] +-[ element : hasNMTOKEN ] +-[ attribute : nmtoken ] "hello“ +-[ ignorable ] +-[ ignorable ] +-[ ignorable ] +-[ element : hasEnumeration ] +-[ attribute : enumeration ] "true“ +-[ ignorable ] +-[ ignorable ] +-[ ignorable ] +-[ element : hasMixed ] +-[ text ] “ “ +-[ text ] " This is text.“ +-[ text ] “ Whitespace normalized Whitespace preserved

 2002 Prentice Hall, Inc. All rights reserved. Outline Output from Fig “ +-[ text ] " “ +-[ element : hasCDATA ] +-[ attribute : cdata ] " simple cdata“ +-[ text ] “ “ +-[ text ] " This is some additional text.“ +-[ text ] “ “ +-[ text ] " “ +-[ ignorable ] +-[ ignorable ] [ document end ]

 2002 Prentice Hall, Inc. All rights reserved. 6.9 Case Study: Writing a DTD for the Day Planner Application Continue case study from Chapter 5 –External subset of DTD for day planner

 2002 Prentice Hall, Inc. All rights reserved. Outline Fig. 6.15DTD for planner.xml. Root element planner Element year contains one or more date elements Element year contains attribute value that has character data Element date contains one or more note elements Element date contains attributes month and day Element note contains parsed character data and optional attribute time Root element planner contains any number of (optional) year elements Element year contains one or more date elements Element year contains attribute value that has character data Element date contains one or more note elements Element date contains attributes month and day, which contain has character data Element note contains parsed character data and optional attribute time

 2002 Prentice Hall, Inc. All rights reserved. Fig DTD for planner.xml.