XP New Perspectives on XML Tutorial 3 1 DTD Tutorial – Carey ISBN 0-619-10187-3.

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.
3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures.
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.
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.
Tutorial 9 Working with XHTML. XP Objectives Describe the history and theory of XHTML Understand the rules for creating valid XHTML documents Apply a.
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
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.
XP New Perspectives on XML Tutorial 4 1 XML Schema Tutorial – Carey ISBN Working with Namespaces and Schemas.
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.
Validating DOCUMENTS with DTDs
XP Tutorial 9New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with XHTML Creating a Well-Formed Valid Document Tutorial 9.
XP The University of Akron Summit College Business Technology Department Computer Information Systems 2440: 140 Internet Tools Instructor: Enoch E. Damson.
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.
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
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.
XML (2) DTD Sungchul Hong.
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.
Copyrighted material John Tullis 10/17/2015 page 1 04/15/00 XML Part 3 John Tullis DePaul Instructor
XML 2nd EDITION Tutorial 1 Creating An Xml Document.
New Perspectives on XML, 2nd Edition
IS432: Semi-Structured Data Dr. Azeddine Chikh. 4. Document Type Definitions (DTDs)
XP 1 New Perspectives on XML Binding XML Data with Internet Explorer.
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
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Understanding How XML Works Ellen Pearlman Eileen Mullin Programming the.
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.
The Official 2002 XML Marathon April 4, Revised Requirements A photocopy of the original text A short description (read: single paragraph) discussing.
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
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.
XP Tutorial 9New Perspectives on HTML and XHTML, Comprehensive 1 Working with XHTML Creating a Well-Formed Valid Document Tutorial 9.
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.
Tutorial 9 Working with XHTML. New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 2 Objectives Describe the history and theory of XHTML.
DTDs© Aptech Limited DTDs 03. DTDs© Aptech LimitedDTDs© Aptech Limited Document Type Definition  In this first lesson, Document Type Definition, you.
Tutorial 9 Working with XHTML. XP Objectives Describe the history and theory of XHTML Understand the rules for creating valid XHTML documents Apply 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
Creating an XML Document
New Perspectives on XML
Session II Chapter 6 – Creating DTDs
Document Type Definition (DTD)
Review of XML IST 421 Spring 2004 Lecture 5.
New Perspectives on XML
Presentation transcript:

XP New Perspectives on XML Tutorial 3 1 DTD Tutorial – Carey ISBN

XP New Perspectives on XML Tutorial 3 2 Creating a Valid Document You validate documents to make certain necessary elements are never omitted. For example, each customer order should include a customer name, address, and phone number. Some elements and attributes may be optional, for example an address. An XML document can be validated using either DTDs (Document Type Definitions) or schemas.

XP New Perspectives on XML Tutorial 3 3 Customer Information Collected by Kristen This figure shows customer information collected by Kristen

XP New Perspectives on XML Tutorial 3 4 The Structure of Kristen’s Document This figure shows the overall structure of Kristen’s document

XP New Perspectives on XML Tutorial 3 5 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 a specific data structure –Specify the use of attributes and define their possible values –Define default values for attributes –Describe how the parser should access non-XML or non-textual content

XP New Perspectives on XML Tutorial 3 6 Declaring a DTD There can only be one DTD per XML document. A document type definition is a collection of rules or declarations that define the content and structure of the document. A document type declaration attaches those rules to the document’s content. You create a DTD by first entering a document type declaration into your XML document. DTD in this tutorial will refer to document type definition and not the declaration. While there can only be one DTD, it can be divided into two parts: an internal subset and an external subset.

XP New Perspectives on XML Tutorial 3 7 Declaring a DTD An internal subset is declarations placed in the same file as the document content. An external subset is located in a separate file. The DOCTYPE declaration for an internal subset is: <!DOCTYPE root [ declarations ]> Where root is the name of the document’s root element, and declarations are the statements that comprise the DTD.

XP New Perspectives on XML Tutorial 3 8 Declaring a DTD The DOCTYPE declaration for external subsets can take two forms: one that uses a SYSTEM location and one that uses a PUBLIC location. The syntax is: or Here, root is the document’s root element, identifier is a text string that tells an application how to locate the external subset, and URL is the location and filename of the external subset. Use the PUBLIC location form when the DTD needs to be limited to an internal system or when the XML document is part of an old SGML application.

XP New Perspectives on XML Tutorial 3 9 Declaring a DTD The SYSTEM location form specifies the name and location of the external subset through the “URL” value. Unless your application requires a public identifier, you should use the SYSTEM location form. A DOCTYPE declaration can indicate both an external and an internal subset. The syntax is: <!DOCTYPE root SYSTEM “URL” [ declarations ]> or <!DOCTYPE root PUBLIC “identifier” “URL” [ declarations ]>

XP New Perspectives on XML Tutorial 3 10 Declaring a DTD If you place the DTD within the document, it is easier to compare the DTD to the document’s content. However, the real power of XML comes from an external DTD that can be shared among many documents written by different authors. If a document contains both an internal and an external subset, the internal subset takes precedence over the external subset if there is a conflict between the two. This way, the external subset would define basic rules for all the documents, and the internal subset would define those rules specific to each document.

XP New Perspectives on XML Tutorial 3 11 Combining an External and Internal DTD Subset This figure shows how to combine an external and an internal DTD subset

XP New Perspectives on XML Tutorial 3 12 Writing the Document Type Declaration This figure shows how to insert an internal DTD subset document comment DTD statements are inserted here the root element of the document must match the root element listed in the DOCTYPE declaration the root element

XP New Perspectives on XML Tutorial 3 13 Declaring Document Elements Every element used in the document must be declared in the DTD for the document to be valid. An element type declaration specifies the name of the element and indicates what kind of content the element can contain. The element declaration syntax is: Where element is the element name and content-model specifies what type of content the element contains.

XP New Perspectives on XML Tutorial 3 14 Declaring Document Elements The element name is case sensitive. DTDs define five different types of element content: –Any elements. No restrictions on the element’s content. –Empty elements. The element cannot store any content.

XP New Perspectives on XML Tutorial 3 15 Types of Element Content ANY content: The declared element can store any type of content. The syntax is: EMPTY content: This is reserved for elements that store no content. The syntax is: –Character data. The element can only contain a text string. –Elements. The element can only contain child elements. –Mixed. The element contains both a text string and child elements.

XP New Perspectives on XML Tutorial 3 16 Types of Element Content CHARACTER content: These elements can only contain text strings. The syntax is: – The keyword #PCDATA stands for “parsed-character data” and is any well-formed text string. ELEMENT content.: The syntax for declaring that elements contain only child elements is: Where child elements is a list of child elements. The declaration indicates the Customer element can only have one child, named Phone. You cannot repeat the same child element more than once with this declaration.

XP New Perspectives on XML Tutorial 3 17 Element Sequences and Choices A sequence is a list f elements that follow a defined order. The syntax is: The order of the child elements must match the order defined in the element declaration. A sequence can be applied to the same child element. Thus, indicates the Customer element should contain three child elements named Phone.

XP New Perspectives on XML Tutorial 3 18 Element Sequences and Choices Choice is the other way to list child elements and presents a set of possible child elements. The syntax is: where child1, child2, etc. are the possible child elements of the parent element. For example, This allows the Customer element to contain either the Name element or the Company element. However, you cannot have both the Customer and the Name child elements since the choice model allows only one of the child elements.

XP New Perspectives on XML Tutorial 3 19 Modifying Symbols Modifying symbols are symbols appended to the content model to indicate the number of occurrences of each element. There are three modifying symbols: –a question mark (?), allow zero or one of the item. –a plus sign (+), allow one or more of the item. –an asterisk (*), allow zero or more of the item. For example, would allow the document to contain one or more Name elements to be placed within the Customer element. Modifying symbols can be applied within sequences or choices. They can also modify entire element sequences or choices by placing the character immediately following the closing parenthesis of the sequence or choice.

XP New Perspectives on XML Tutorial 3 20 Mixed Content Mixed content elements contain both character data and child elements. The syntax is: This form applies the * modifying symbol to a choice of character data or elements. Therefore, the parent element can contain character data or any number of the specified child elements, or it can contain no content at all. Because you cannot constrain the order in which the child elements appear or control the number of occurrences for each element, it is better not to work with mixed content if you want a tightly structured document.

XP New Perspectives on XML Tutorial 3 21 Declaring Element Attributes For a document to be valid, all the attributes associated with elements must also be declared. To enforce attribution properties, you must add an attribute-list declaration to the document’s DTD.

XP New Perspectives on XML Tutorial 3 22 Declaring Element Attributes The attribute-list declaration : –Lists the names of all attributes associated with a specific element –Specifies the data type of the attribute –Indicates whether the attribute is required or optional –Provides a default value for the attribute, if necessary The syntax to declare a list of attributes is: <!ATTLIST element attribute1 type1 default1 attribute2 type2 default2 attribute3 type3 default3…> Where element is the name of the element associated with the attributes, attribute is the name of an attribute, type is the attribute’s data type, and default indicates whether the attribute is required or implied, and whether it has a fixed or default value. Attribute-list declaration can be placed anywhere within the document type declaration, although it is easier if they are located adjacent to the declaration for the element with which they are associated.

XP New Perspectives on XML Tutorial 3 23 Working with Attribute Types While all attribute types are text strings, you can control the type of text used with the attribute. There are three general categories of attribute values: –string –enumerated –Tokenized String types are the simplest form and can contain any character except those reserved by XML. Enumerated types are attributes that are limited to a set of possible values. The general for of an enumerated type is: attribute (value1 | value2 | value3 | …) For example, the following declaration: Customer CustType (home | business )> restricts CustType to either “home” or “business”

XP New Perspectives on XML Tutorial 3 24 Working with Attribute Types Another type of enumerated attribute is notation. It associates the value of the attribute with a declaration located elsewhere in the DTD. The notation provides information to the XML parser about how to handle non-XML data. Tokenized types are text strings that follow certain rules for the format and content. The syntax is: attribute token There are seven tokenized types. For example, the ID token is used with attributes that require unique values. For example, if a customer ID needs to be unique, you may use the ID token: Customer CustID ID This ensures each customer will have a unique ID.

XP New Perspectives on XML Tutorial 3 25 Attribute Tokens This figure shows the seven attribute tokens

XP New Perspectives on XML Tutorial 3 26 Attribute Defaults The final part of an attribute declaration is the attribute default. There are four possible defaults: –#REQUIRED: the attribute must appear with every occurrence of the element. –#IMPLIED: The attribute is optional. –An optional default value: A validated XML parser will supply the default value if one is not specified. –#FIXED: The attribute is optional but if one is specified, it must match the default.

XP New Perspectives on XML Tutorial 3 27 Inserting Attribute-List Declarations This figure the revised contents of the Orders.xml file attribute declaration

XP New Perspectives on XML Tutorial 3 28 Working with Entities Entities are storage units for a document’s content. The most fundamental entity is the XML document itself and is known as the document entity. Entities can also refer to: –a text string –a DTD –an element or attribute declaration –an external file containing character or binary data Entities can be declared in a DTD. How to declare an entity depends on how it is classified. There are three factors involved in classifying entities:

XP New Perspectives on XML Tutorial 3 29 General Parsed Entities General entities are declared in the DTD of a document. The syntax is: Where entity is the name assigned to the entity and value is the general entity’s value. For example, an entity named “Pixal” can be created to store a company's official name: After an entity is declared, it can be referenced anywhere within the document. This is the home page of &Pixal;. This is interpreted as This is the home page of Pixal Digital Products

XP New Perspectives on XML Tutorial 3 30 Entities in the ITEMS.DTD File This figure shows the entities in the ITEMS.DTD file entity nameentity value

XP New Perspectives on XML Tutorial 3 31 General External Entities General entities can refer to values located in external files. The syntax is: For example, in the declaration: An entity named “headlines” gets its value from the document, stories.xml located at

XP New Perspectives on XML Tutorial 3 32 Parameter Entities Parameter entities are used to store the content of a DTD. For internal parameter entities, the syntax is: where entity is the name of the parameter entity and value is a text string of the entity’s value. For external parameter entities, the syntax is: where URL is the name assigned to the parameter entity. Parameter entity references can only be placed where a declaration would normally occur, such as an internal or external DTD. Parameter entities used with an internal DTD do not offer any time or effort savings. However, an external parameter entity can allow XML to use more than one DTD per document by combining declarations from multiple DTDs.

XP New Perspectives on XML Tutorial 3 33 Using Parameter Entities to Combine Multiple DTDs This figure shows how to combine multiple DTDs using parameter entities

XP New Perspectives on XML Tutorial 3 34 Unparsed Entities You need to create an unparsed entity in order to reference binary data such as images or video clips, or character data that is not well formed. The unparsed entity includes instructions for how the unparsed entity should be treated. A notation is declared that identifies a resource to handle the unparsed data. For example, to create a notation named “audio” that points to an application Recorder.exe: Once the notation has been declared, you then declare an unparsed entity that instructs the XML parser to associate the data to the notation.

XP New Perspectives on XML Tutorial 3 35 Unparsed Entities For example, to take unparsed data in an audio file and assign it to an unparsed entity named “Theme:”, use the following: Here, the notation is the audio notation that points to the Recorder.exe file. This declaration does not tell the Record.exe application to run the file but simply identifies for the XML parser what resource is able to handle the unparsed data.