DTDs© Aptech Limited DTDs 03. DTDs© Aptech LimitedDTDs© Aptech Limited Document Type Definition  In this first lesson, Document Type Definition, you.

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.
1 XML DTD & XML Schema Monica Farrow G30
3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures.
Introduction to XML: DTD
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.
CS 898N – Advanced World Wide Web Technologies Lecture 21: XML Chin-Chih Chang
Document Type Definitions
XML Schemas Microsoft XML Schemas W3C XML Schemas.
CSCI 7818 (Topics in Software Engineering) Web Infrastructure, Services, and Applications Document Type Definition (DTD) Author: Lukasz Kurgan.
 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.
Document Type Definitions. XML and DTDs A DTD (Document Type Definition) describes the structure of one or more XML documents. Specifically, a DTD describes:
Introducing XHTML: Module B: HTML to XHTML. Goals Understand how XHTML evolved as a language for Web delivery Understand the importance of DTDs Understand.
Introducing HTML & XHTML:. Goals  Understand hyperlinking  Understand how tags are formed and used.  Understand HTML as a markup language  Understand.
Copyright © 2003 Pearson Education, Inc. Slide 2-1 Created by Cheryl M. Hughes, Harvard University Extension School — Cambridge, MA The Web Wizard’s Guide.
ECA 228 Internet/Intranet Design I Intro to XML. ECA 228 Internet/Intranet Design I HTML markup language very loose standards browsers adjust for non-standard.
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.
XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.
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.
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 Extensible Markup Language. What is XML? ● meta-markup language ● a language for defining a family of languages ● semantic/structured mark-up language.
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.
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.
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.
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.
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.
XML Documents Chao-Hsien Chu, Ph.D. School of Information Sciences and Technology The Pennsylvania State University Elements Attributes Comments PI Document.
IS432 Semi-Structured Data Lecture 2: DTD Dr. Gamal Al-Shorbagy.
Introduction to XML This presentation covers introductory features of XML. What XML is and what it is not? What does it do? Put different related technologies.
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
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.
CSE3201 Information Retrieval Systems DTD Document Type Definition.
Document Type Definitions (DTD) A Document Type Definition (DTD) defines the structure and the legal elements and attributes of an XML document. A DTD.
INFSY 547: WEB-Based Technologies Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 4 1COMP9321, 15s2, Week.
225 City Avenue, Suite 106 Bala Cynwyd, PA , phone , fax presents… XML Syntax v2.0.
Introduction to DTD A Document Type Definition (DTD) defines the legal building blocks of an XML document. It defines the document structure with a list.
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.
XML CORE CSC1310 Fall XML DOCUMENT XML document XML document is a convenient way for parsers to archive data. In other words, it is a way to describe.
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.
Session III Chapter 6 – Creating DTDs
New Perspectives on XML
Session II Chapter 6 – Creating DTDs
Presentation transcript:

DTDs© Aptech Limited DTDs 03

DTDs© Aptech LimitedDTDs© Aptech Limited Document Type Definition  In this first lesson, Document Type Definition, you will learn to:  Define what is meant by a DTD.  Identify the need for a DTD. 2

DTDs© Aptech LimitedDTDs© Aptech Limited Definition of a DTD  Is a non XML document made up of element, attribute, and entity declarations.  Helps XML parsers to validate the XML document.  Helps authors to set default values for element attributes.  Document's tree structure can be determined based on the DTD. 3

DTDs© Aptech LimitedDTDs© Aptech Limited Need for a DTD  DTD was introduced to fulfil the need for some sort of standardization of elements and attributes in an XML document.  A DTD:  Can define all the possible combinations and sequences for elements to be used in an XML document along with their attributes and their acceptable values. 4

DTDs© Aptech LimitedDTDs© Aptech Limited DTD versus DOCTYPE 1-3  Table lists difference between a Document Type Definition (DTD) and a Document Type Declaration (DOCTYPE). 5 PropertiesDocument Type DefinitionDocument Type Declaration DefinitionA list of legal element, attribute and entity declarations for an XML document. The declaration of the DTD to which the XML document adheres to. AbbreviationDTDDOCTYPE LocationWithin the DOCTYPE declaration or an external file Within the XML document's prolog Syntax Or Language TypeNon XMLXML VariationsPresent within a DOCTYPE (Internal DTD) or in an external document (External DTD) Declaring either an internal or external DTD DependencyIs useful only if declared using DOCTYPE declaration Is useful only if it has a DTD to define

DTDs© Aptech LimitedDTDs© Aptech Limited  DOCTYPE declarations :  Can declare DTDs within themselves or refer to DTDs present in external documents termed as internal or external respectively.  The example shows how to declare a DTD within a DOCTYPE declaration. 6 Snippet File: Mobile.xml... <!DOCTYPE Mobile [ ]>... DTD versus DOCTYPE 2-3

DTDs© Aptech LimitedDTDs© Aptech Limited  The example displays the same DTD shown in the previous example but in the form of an external DTD.  The DTD is declared in a separate file "Mobile.dtd". The DOCTYPE declaration in the XML file refers to it using the SYSTEM keyword. 7 Snippet File: Mobile.dtd File: Mobile.xml DTD versus DOCTYPE 3-3

DTDs© Aptech LimitedDTDs© Aptech Limited Limitations of DTD 8 DTDs validate XML documents but themselves are non-XML documents, so cannot boast extensibility. DTDs can be either external or internal depending on their DOCTYPE declaration. This limits the advantage of having both internal and external DTDs. DTDs do not follow the latest trends of being object oriented, inheritance, and so on. XML documents can use multiple namespaces. However, DTDs do not support multiple namespaces. DTDs support only one datatype, the text string. Being able to define DTDs for standardizing XML documents is surely one of DTDs biggest tenets. Internal DTDs being able to override external DTDs creates malicious internal DTDs. Thus, the security aspect of DTDs is very doubtful.

DTDs© Aptech LimitedDTDs© Aptech Limited Working with DTDs  In this second lesson, Working with DTDs, you will learn to:  Describe the structure of a DTD.  Explain how to create a simple DTD.  Describe what is meant by document type declarations. 9

DTDs© Aptech LimitedDTDs© Aptech Limited Structure of DTD  A typical DTD structure is composed of the following three blocks that can be declared in any sequence.  Element declaration: Specifies the name of the element, and the content which that element can contain.  Attribute declaration: Specifies the element that owns the attribute, the attribute name, its type, and its default value.  Entity declaration: Specifies the name of the entity and either its value or location of its value. 10 Element Declarations Attribute Declarations Entity Declarations

DTDs© Aptech LimitedDTDs© Aptech Limited Creating Internal DTDs 1-2  Creating DTDs is a simple six step process that can be listed as follows: 1.Declare all the possible elements. 2.Specify the permissible element children, if any. 3.Set the order in which elements must appear. 4.Declare all the possible element attributes. 5.Set the attribute data types and values. 6.Declare all the possible entities.  Steps 1 to 3 deal with element declaration.  Steps 4 and 5 with attribute declarations.  Step 6 with entity declarations. 11 Syntax … … …

DTDs© Aptech LimitedDTDs© Aptech Limited Creating Internal DTDs 2-2  The code demonstrates the properties of internal DTDs. 12 Snippet

DTDs© Aptech LimitedDTDs© Aptech Limited DOCTYPE Declarations 1-2  Declares that the XML file in which it is present adheres to a certain DTD.  Specifies the name of that DTD and either its content or location.  Placed in the XML document's prolog.  Declaration begins with.  In between is the name of the root element, followed either by a pair of square brackets containing the DTD itself or by the SYSTEM keyword and a URL specifying where the DTD can be found. 13

DTDs© Aptech LimitedDTDs© Aptech Limited DOCTYPE Declarations 2-2  Figure shows the DOCTYPE declaration. 14 Syntax Or

DTDs© Aptech LimitedDTDs© Aptech Limited Types of DTDs  Internal DTDs:  Are characterized by the presence of the DTD in the document type declaration itself.  Consists of the DTD name followed by the DTD enclosed in square brackets.  Figure depicts the internal DTD.  External DTDs:  Are characterized by the presence of the DTDs address path in the document type declaration.  Consists of the DTDs name followed by the SYSTEM keyword followed by the address of the DTD document.  Figure depicts the external DTD. 15

DTDs© Aptech LimitedDTDs© Aptech Limited Valid XML Documents  In this third lesson, Valid XML Documents, you will learn to:  Define document validity.  Describe in brief how to test for document validity. 16

DTDs© Aptech LimitedDTDs© Aptech Limited Well-Formed XML Documents  A well-formed XML document adheres to the basic XML syntax rules.  Basic XML syntax rules are as follows:  All elements must be enclosed by the root element.  All elements must have closing tags.  All tags should be case sensitive.  All elements must be properly nested.  All attribute values must always be quoted.  Figure shows an example of well-formed XML document. 17

DTDs© Aptech LimitedDTDs© Aptech Limited Valid XML Documents 1-2  Is a well-formed XML document that adheres to its DTD.  Is determined by checking it against its DTD.  Plays an important role in all XML applications.  Adhere to the declarations in the DTD, a well-formed XML document can be termed as a valid XML document. 18

DTDs© Aptech LimitedDTDs© Aptech Limited  The code demonstrates a valid XML document. <!DOCTYPE Mail [ ]> 27th February :30 am Meeting at Main Conference Room at 4:30pm Hi, Kindly request you to attend the cultural body general meeting in the main conference room at 4:30 pm. Please be present to learn about the new activities being planned for the employees for this year. Yours sincerely, Bob Valid XML Documents Snippet

DTDs© Aptech LimitedDTDs© Aptech Limited Testing XML for Validity  Validity of XML documents can be determined by using a validating parser such as MSXML 6.0 Parser.  To validate the code in the Internet Explorer (IE):  Once the code is displayed in IE, right-click the code to display the context menu.  The menu provides the option of validating the code.  On selection, IE internally validates the code against the code's DTD.  Figure displays the validation result of a valid mobile.xml file as well as the validation result after the removal of the signature element from the document's DTD. 20

DTDs© Aptech LimitedDTDs© Aptech Limited Declarations  In this last lesson, Declarations, you will learn to:  Explain how to declare elements.  Explain how to declare attributes.  Describe entity declaration in a DTD. 21

DTDs© Aptech LimitedDTDs© Aptech Limited Declaring Elements 1-4  In the DTD, XML elements are declared with an element declaration. where,  ELEMENT is the keyword.  element-name is the name of the element.  element-rule can be one of the following: No Content, Only Parsed Character Data, Any Contents, Children, Only One Occurrence, Minimum One Occurrence, Zero or More Occurrences, Zero or One Occurrence, Either/Or Content, or Mixed Content.  Figure depicts an example of element declaration. 22 Syntax

DTDs© Aptech LimitedDTDs© Aptech Limited Declaring Elements 2-4  Table lists the syntax and declarations for the element-rule options. 23 ValueDescriptionSyntaxExample No ContentThese elements are empty and accept no data. Only Parsed Character Data Elements contain character data that needs to be parsed. Any ContentsElements can contain any combination of data that can be parsed. ChildrenElements with one or more children are defined with the name of the children elements inside parentheses followed by their declarations in the same order. or …

DTDs© Aptech LimitedDTDs© Aptech Limited Declaring Elements 3-4  Table lists shows additional declarations. 24 ValueDescriptionSyntaxExample Only One OccurrenceElements with children declared only once within the parentheses implicitly appear only once in the XML document. Minimum One OccurrenceElement children names accompanied by a ‘+’ sign inside the parentheses should appear at least once in the XML document. Zero or More OccurrencesElements with children names accompanied by a ‘*’ sign inside the parentheses can or cannot appear in the XML document. Zero or One OccurrencesElements with children names accompanied by a ‘?’ sign inside the parentheses can be skipped or only appear once in the XML document.

DTDs© Aptech LimitedDTDs© Aptech Limited Declaring Elements ValueDescriptionSyntaxExample Either/Or ContentElements can have either one of two or more children by specifying them in parentheses separated by ‘|’. Mixed ContentElements can be declared to accept mixed content, either data type or children, etc.

DTDs© Aptech LimitedDTDs© Aptech Limited Declaring Attributes where,  element-name is the element the attribute belongs to,  attribute-name is the name of the attribute,  attribute-type is type of data the attribute can accept,  default-value is the default value for the attribute.  Table lists the attribute-type values. 26 Syntax ValueDescription PCDATAParsed character data CDATACharacter data (en1|en2|..)Enumerated list IDA unique id IDREFId of another element IDREFSList of other ids NMTOKENValid XML name NMTOKENSList of valid XML names ENTITYAn entity ENTITIESList of entities NOTATIONName of a notation xml:Predefined xml value

DTDs© Aptech LimitedDTDs© Aptech Limited Specifying Attribute Values 1-2  Table lists the attribute–value in a DTD declaration.  #IMPLIED   #REQUIRED   #FIXED   Enumerated Attribute Values  27 ValueDescription valueDefault value #REQUIREDValue must be included #IMPLIEDValue does not have to be included #FIXEDValue is fixed en1|en2|...Listed enumerated values

DTDs© Aptech LimitedDTDs© Aptech Limited Specifying Attribute Values 2-2  The code demonstrates the attribute values Default Value --#IMPLIED --#REQUIRED --#FIXED --Enumerated Attribute Values Snippet

DTDs© Aptech LimitedDTDs© Aptech Limited Entities in DTD 1-3  An XML entity:  Is a placeholder that consists of a name and a value.  Is declared once and then repeatedly used through out the document in place of its value.  Can be categorized as parameter entities and general entities.  General entities:  Character  Mixed Content  Unparsed  Character entities:  Pre-defined  Numbered  Name 29

DTDs© Aptech LimitedDTDs© Aptech Limited Entities in DTD 2-3  Table lists the Pre-defined entities and their references.  Numbered entities are entities which use a character reference number, for a character from the Unicode character set, in place of the character itself.  &#x(reference number in hexadecimal);  Name entities are the same as Numbered entities, except that the numbers are replaced by a descriptive name for the character.  Mixed content entities are entities that contain either text or markup language text as their replacement value.  Unparsed entities are entities that have data that is not to be parsed.  Example : <!DOCTYPE name [ ]> 30 Entity NameValue amp & apos ' gt > lt < quot "

DTDs© Aptech LimitedDTDs© Aptech Limited Entities in DTD 3-3  Entity declaration  Entity Reference  Figure depicts the entities in DTD. 31 Syntax Syntax &entity-name;

DTDs© Aptech LimitedDTDs© Aptech Limited Kinds of Entity Declarations 1-3  Internal Entity Declaration  In internal entity declarations, the entity value is explicitly mentioned in the entity declaration.  The code demonstrates the properties of internal entity declaration. 32 Syntax <!DOCTYPE Mobile [ ]> Nokia &HP;, &CH; and a &SK; Snippet

DTDs© Aptech LimitedDTDs© Aptech Limited Kinds of Entity Declarations 2-3  External Entity Declaration  In External entity declaration, a link or path to the entity value is mentioned in place of the entity value with the help of the SYSTEM keyword.  The code demonstrates the properties of external entity declaration. 33 Syntax <!DOCTYPE Mobile [ ]> Snippet

DTDs© Aptech LimitedDTDs© Aptech Limited Kinds of Entity Declarations Nokia &HP;, &CH; and a &SK; hp.txt Head Phones ch.txt Charger sk.txt Starters Kit Snippet

DTDs© Aptech LimitedDTDs© Aptech Limited Summary  In this module, Document Type Definitions, you learnt about:  Document Type Definition  This lesson defines DTDs and identifies the need for DTDs.  Working with DTDs  This lesson talks about the structure of DTDs, steps to create DTDs, DOCTYPE declarations, and the type of DTDs.  Valid XML Documents  This lesson talks about the well-formed valid documents and the steps to determine the validity of XML documents.  Declarations  This lesson deals with declarations of elements, attributes, and entities in DTDs. 35