McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Creating Document Type Definitions (DTDs) Ellen Pearlman Eileen Mullin.

Slides:



Advertisements
Similar presentations
CSCI N241: Fundamentals of Web Design Copyright ©2004 Department of Computer & Information Science Introducing XHTML: Module B: HTML to XHTML.
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 Study-Session: Part II Validating XML Documents.
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
 2002 Prentice Hall, Inc. All rights reserved. ISQA 407 XML/WML Winter 2002 Dr. Sergio Davalos.
Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.
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
Introducing XHTML: Module B: HTML to XHTML. Goals Understand how XHTML evolved as a language for Web delivery Understand the importance of DTDs Understand.
Introduction to XML This material is based heavily on the tutorial by the same name at
Introducing HTML & XHTML:. Goals  Understand hyperlinking  Understand how tags are formed and used.  Understand HTML as a markup language  Understand.
XP New Perspectives on XML Tutorial 4 1 XML Schema Tutorial – Carey ISBN Working with Namespaces and Schemas.
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
Pemrograman Berbasis WEB XML part 2 -Aurelio Rahmadian- Sumber: w3cschools.com.
Internet Skills An Introduction to HTML Alan Noble Room 504 Tel: (44562 internal)
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.
CREATED BY ChanoknanChinnanon PanissaraUsanachote
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Schemas Ellen Pearlman Eileen Mullin Programming the Web Using XML.
XML CPSC 315 – Programming Studio Fall 2008 Project 3, Lecture 1.
XP 1 CREATING AN XML DOCUMENT. XP 2 INTRODUCING XML XML stands for Extensible Markup Language. A markup language specifies the structure and content of.
Document Type Definitions Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
1 herbert van de sompel CS 502 Computing Methods for Digital Libraries Cornell University – Computer Science Herbert Van de Sompel
XHTML1 Building Document Structure Chapter 2. XHTML2 Objectives In this chapter, you will: Learn how to create Extensible Hypertext Markup Language (XHTML)
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
XHTML. Introduction to XHTML What Is XHTML? – XHTML stands for EXtensible HyperText Markup Language – XHTML is almost identical to HTML 4.01 – XHTML is.
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.
What is XML?  XML stands for EXtensible Markup Language  XML is a markup language much like HTML  XML was designed to carry data, not to display data.
Tutorial 1: XML Creating an XML Document. 2 Introducing XML XML stands for Extensible Markup Language. A markup language specifies the structure and content.
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.
XML A web enabled data description language 4/22/2001 By Mark Lawson & Edward Ryan L’Herault.
Copyrighted material John Tullis 10/17/2015 page 1 04/15/00 XML Part 3 John Tullis DePaul Instructor
New Perspectives on XML, 2nd Edition
IS432 Semi-Structured Data Lecture 2: DTD Dr. Gamal Al-Shorbagy.
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
1 Introduction to XML XML stands for Extensible Markup Language. Because it is extensible, XML has been used to create a wide variety of different markup.
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.
The eXtensible Markup Language (XML). Presentation Outline Part 1: The basics of creating an XML document Part 2: Developing constraints for a well formed.
1 Tutorial 11 Creating an XML Document Developing a Document for a Cooking Web Site.
XML 2nd EDITION Tutorial 4 Working With Schemas. XP Schemas A schema is an XML document that defines the content and structure of one or more XML documents.
1 Tutorial 14 Validating Documents with Schemas Exploring the XML Schema Vocabulary.
Tutorial 13 Validating Documents with Schemas
INFSY 547: WEB-Based Technologies Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2.
QUALITY CONTROL WITH SCHEMAS CSC1310 Fall BASIS CONCEPTS SchemaSchema is a pass-or-fail test for document Schema is a minimum set of requirements.
HTML Basics. HTML Coding HTML Hypertext markup language The code used to create web pages.
Document Type Definition (DTD) Eugenia Fernandez IUPUI.
XML Validation. a simple element containing text attribute; attributes provide additional information about an element and consist of a name value pair;
 XML derives its strength from a variety of supporting technologies.  Structure and data types: When using XML to exchange data among clients, partners,
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
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.
XML BASICS and more…. What is XML? In common:  XML is a standard, simple, self-describing way of encoding both text and data so that content can be processed.
Session III Chapter 6 – Creating DTDs
New Perspectives on XML
Session II Chapter 6 – Creating DTDs
New Perspectives on XML
Presentation transcript:

McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Creating Document Type Definitions (DTDs) Ellen Pearlman Eileen Mullin Programming the Web Using XML

4-2 Learning Objectives 1.Understanding the function and syntax of a DTD 2.Learning what distinguishes internal and external subsets of DTDs 3.Defining the order and frequency of elements 4.Understanding how to create attributes and apply them to elements 5.Exploring how entity declarations and notation elements work.

4-3 XML’s Schema Languages There are two common schema languages used in XML. –The first is the Document Type Definition (DTD), which defines the grammar and vocabulary of your markup language. The DTD lists everything that a parser needs to know in order to display and process your XML document. –The second common schema language is XML Schema, which is well-suited for more complex XML documents.

4-4 Introducing DTDs A DTD uses grammar and structure to bring order to the elements of a markup language defined by XML. To stipulate grammatical rules, a DTD compares a set of expressions against predefined patterns in an XML document to figure out whether that document is valid or not The matching is very nitpicky - for example, pressing the space bar twice when the processor is looking for a single blank space is a mismatch.

4-5 Checking for Validation As you gain experience writing XML documents, consider using a validating parser – a parser that refers to your DTD in scanning your documents for errors. –An interactive validation process pops up warnings and error messages as you're constructing an XML document. –With a parser that performs batch validation, you submit a complete XML document for error- checking and then see a complete report listing all errors and warnings that may apply.

4-6 Tracking Validated Files with TIBCO TurboXML

4-7 Example: An Online XML Validator

4-8 Proofread Your Own Code in Addition to Validating It While using a validating parser is a good way to catch mistakes, it’s not a substitute for your own careful review of your code. For example, your parser will note if a song title is missing from an XML document containing lyrics if the songbook DTD states that every song must have a title. If, however, an entire verse is omitted, the parser will not complain as long as the DTD contains no rules governing how many verses are in a song.

4-9 Using DTD Syntax A DTD consists of a number of declarations. Each declaration is assigned to one of the following categories: –ELEMENT, for defining tags –ATTLIST, for specifying attributes in your tags –ENTITY, for identifying sources of data –NOTATION, for defining data types for non-XML data

4-10 Internal and External DTDs The declarations that make up a DTD can be stored either at the beginning of an XML document or in an external file. Each method has its own advantages. –When the declarations in a DTD are stored with the document it describes, you can easily move the file to a new location and have the DTD travel with it. –However, it’s often most efficient to create an external DTD that you can reference from many different files.

4-11 Writing Element Declarations An element declaration is used to define a new tag and specify what kind of content it can contain. –The declaration begins with an opening bracket (<) and exclamation point (!) followed by the keyword ELEMENT. –The name of the element you’re declaring follows next; it’s often called a generic identifier. –The rest of the tag states what content is allowed in the element, also known as the content specification.

4-12 Model Groups A model group defines an element that may contain tokens. These are other elements (called child elements) or an element that contains a combination of both document text and child elements. The element declaration: creates a tag that contains other tags as shown below: Marge Piercy

4-13 Controlling Quantity You can impose requirements about how often each element can be used. For example, some books may have more than one author. Accordingly, you could add a requirement that while an element called book must have at least one author, but could have more:

4-14 Controlling Order When you define two or more tokens in an element, you can also control the order in which the child elements should appear. The declaration for an element called flight might appear as follows: could be used to generate the following code fragment: United 21 LGA SFO July 27

4-15 Controlling Order (2) Another way you can control which elements appear is through a choice connector, which indicates that only one of a selection of elements can be used. Instead of commas, the tokens are separated by a pipe character ( | ) in an element declaration: This tagging might be put to use in a clothes catalog, for instance: …

4-16 Ordering Elements : Sequence Connector and Choice Connector

4-17 Free Text Any elements that may contain freeform document text are indicated by the keyword PCDATA preceded by a hash mark (#) in the element declaration. Some examples include: It's also possible to define elements that contain free text as well as child elements:

4-18 Attribute List Declarations

4-19 Parameters for Attribute List Declarations Attribute name. The name of your new attribute is subject to the same restrictions as element names. Attribute type. An attribute’s type can restrict the range of values that the attribute can hold. It can also identify special attributes that may be of importance to the parser. Required or default values. The attribute is set to any value entered here if and when the document author fails to supply another.

4-20 Declarations in Attribute Lists The declarations in attribute lists identify the name, data type, and default value (if there is one) of each attribute associated with a given element type: –Name. This defines the full set of attributes that pertain to a given element type. –Type. Establishes type constraints for the attribute. –Default value. Provides a value to used for that attribute unless it is changed.

4-21 Writing Parameter Entity Declarations Parameter entities are used exclusively for assisting with constructing a DTD. You can use a parameter entity to assign a short name for a model group that’s in common use throughout your documents. You identify a parameter entity by preceding its name in the declaration with a percentage sign (%) and a blank space:

4-22 Writing Notation Declarations In an XML document, an entity or element is permitted to contain non-XML format data. When this happens, the element declaration has to specify which formats may be embedded via a definition in a notation declaration. For example, an XML-based photo catalog might contain graphics file formats (like PNG or TIF) that your processor doesn't recognize. When that happens, you must define the notation:

4-23 Referencing DTDs The declarations that make up a DTD can be stored in one of two locations. –At the top of each of your XML documents. –In a separate data file that’s simply referenced from the XML document. A DOCTYPE declaration is used in both cases. When the DTD declarations are enclosed internally within an XML document, the DOCTYPE declaration lists encloses the list of declarations within a set of square brackets ([ ]).

4-24 Referencing an Internal DTD <!DOCTYPE message [ ]> Ross Bunny July 25 11:15 a.m. Reminder Please don’t forget to tape Survivor tonight!

4-25 Referencing an External DTD Ross Bunny July 25 11:15 a.m. Reminder Please don't forget to tape Survivor tonight! message.dtd

4-26 An Internal Subset of Declarations Is Processed Before an External Subset

4-27 Conditional Sections Another way you can control whether or not certain declarations are accessible to any given document is with a conditional section. This includes instructions that say whether or not a particular set of declarations within an external subset are available. The declarations contained within such a section are only available if all conditions are met.

4-28 Creating External DTD Subsets In order to design and maintain a consistent look across a large body of documents, you need a way to manage your DTD’s declarations centrally. To handle this, you can store some or all of your declarations in a separate file that’s named with a.dtd extension. This kind of file is known as an external subset. <!DOCTYPE termpaper SYSTEM [ ]>

4-29 Using Internal DTD Subsets After you define an external DTD, you may not have many declarations left to include in an internal subset. These leftover declarations typically include entity declarations for important phrases or images that appear frequently within this particular document but not others. An internal subset is also a good place to define special characters used here that aren’t needed in the majority of your documents.

4-30 Using Conditional Sections with Entities You can control whether to include or omit declarations by using a conditional section in a DTD. The keyword INCLUDE specifies when a certain declaration should be included, while the keyword IGNORE dictates when a declaration is excluded: ] ] > Similarly, the following conditional section tells the parser to exclude the declaration of an element called graffiti: ] ] >

4-31 The End