Dtd

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Dtd as PDF for free.

More details

  • Words: 1,961
  • Pages: 48
DTD Document Type Definition

DTD • The DTD defines the constraints on the structure of an XML document. • It declares all of the document's element types , children element types, and the order and number of each element type. It also declares any attributes, entities, notations, processing instructions, comments, in the document.

• Types: – Internal DTD – External DTD

Internal DTD • Syntax:

Example Internal DTD ]> p101 peter

Rules for Internal DTD • The document type declaration must be placed between the XML declaration and the first element (root element) in the document . • The keyword DOCTYPE must be followed by the name of the root element in the XML document . • The keyword DOCTYPE must be in upper case

The External DTD • External DTDs are useful for creating a common DTD that can be shared between multiple documents. • Any changes that are made to the external DTD automatically updates all the documents that reference it. • There are two types of external DTDs: – Private – Public.

Rules for External DTD • If any elements, attributes, or entities are used in the XML document that are referenced or defined in an external DTD, standalone="no" must be included in the XML declaration

Private External DTD • identified by the keyword SYSTEM, • There are intended for use by a single author or group of authors. • Syntax: where: DTD_location: relative or absolute URL

Example for Private external DTD <Employee> <eid>101 kumar

Example contd… The external DTD (“employee.dtd") referenced in the example contains information about the XML document's structure:

Public External DTD • identified by the keyword PUBLIC • Syntax:

• These are intended for broad use. The "DTD_location" is used to find the public DTD if it cannot be located by the "DTD_name".

where: DTD_location: relative or absolute URL DTD_name: follows the syntax "prefix//owner_of_the_DTD//description_of_the_DTD//ISO 639_language_identifier“

Example for Public External DTD <TITLE>A typical HTML file This is the typical structure of an HTML file. It follows the notation of the HTML 4.0 specification, including tags that have been deprecated (hence the "transitional" label).

prefixes • The following prefixes are allowed in the DTD name: Prefix ISO

Definition The DTD is an ISO standard. All ISO standards are approved.

+

The DTD is an approved non-ISO standard.

-

The DTD is an unapproved non-ISO standard.

Element Type Declaration • set the rules for the type and number of elements that may appear in an XML document • what elements may appear inside each other, and • what order they must appear in syntax: example :



Rules for Element Type • All element types used in an XML document must be declared in the Document Type Definition (DTD) using an Element Type Declaration . • An element type cannot be declared more than once . • The name in the element type's end tag must match the name in the element type's start tag . Element names are case sensitive. • The keyword ELEMENT must be in upper case

Declaring multiple children (sequence) • Multiple children are declared using commas (,). •

Commas fix the sequence in which the children are allowed to appear in the XML document.
parent_name child1_name,child2_name,child3_name)> child1_name allowable_contents> child2_name allowable_contents> child3_name allowable_contents>

Rules: All of the children elements must be declared in a separate element type declaration

Allowable contents

EMPTY

ANY

Children elements

Mixed contents

Definition Refers to tags that are empty. , or Refers to anything at all, as long as XML rules are followed You can place any number of element types within another element type Refers to a combination of (#PCDATA) and children elements. (parsed character data -> PCDATA)

Example ]> <student> ECE06117

Declaring zero or more children Zero or more children are declared using the (*) operator. syntax:



]> <student> <subject>Mathematics <subject>Physics <subject>Chemistry

Declaring One or More children One or more children are declared using the (+) operator. syntax:



example: ]> <student> <subject>Mathematics

Combinations of Children A choice between children element types is declared using the (|) operator. syntax: • Example:

]> <student> 9216735

Nested Elements ]> <student> <surname>Smith Jo jerald <sex>female

Example

]> <student> <surname>Smith Josephine Jo

Mixed Content Mixed content is used to declare elements that contain a mixture of children elements and text (PCDATA). syntax: Rules: •(#PCDATA) must come first in the mixed content declaration . •The operator (*) must follow the mixed content declaration if children elements are included

Example 1 ]> <student> Here's a bit of text mixed up with the child element. 9216735 You can put text anywhere, before or after the child element. You don't even have to include the 'id' element.

Example 2
student (#PCDATA|id|surname|dob)*> id (#PCDATA)> surname (#PCDATA)> dob (#PCDATA)> ]>

<student> You can put text anywhere. You can also put the elements in any order in the document. <surname>Smith And, you don't have to include all the elements listed in the element declaration. 9216735

Attribute List Declarations • Attributes are additional information associated with an element type. •The ATTLIST declaration identifies • type of attribute • default value • element types syntax: . . . <element attribute_name="attribute_value"> Rules: •Attributes may only appear in start or empty tags . •The keyword ATTLIST must be in upper case

Example ]>

Attribute types Three main Attribute types: • string type • CDATA – character Data • tokenized types • ID, IDREF, IDREFS, ENTITY,ENTITIES,NMTOKEN,NMTOKENS • enumerated types • NOTATION, ENUMERATED

ID • ID is a unique identifier of the attribute. • IDs of a particular value should not appear more than once in an XML document . • An element type may only have one ID attribute . • An ID attribute can only have an #IMPLIED or #REQUIRED default value . • The first character of an ID value must be a letter, '_', or ':'

CDATA Character data ]>

Example ]>

<student_name student_no="a9216735">Jo Smith

IDREF •IDREF value of the attribute must refer to an ID value declared elsewhere in the document . • The first character of an ID value must be a letter, '_', or ':‘

IDREF Example ]> <student_name student_no="a8904885">Alex Foo <student_name student_no="a9011133">Sarah Bar <student_name student_no="a9216735" tutor_1="a9011133" tutor_2="a8904885">Jo Smith

IDREFS • Allows multiple ID values separated by whitespace

ENTITY • ENTITYs are used to reference data that act as an abbreviation or can be found at an external location. • The first character of an ENTITY value must be a letter, '_', or ':‘ EXAMPLE:

]> <experiment_a> &name;

NMTOKEN The first character of an NMTOKEN value must be a letter, digit, '.', '-', '_', or ':‘ Example: ]> <student_name student_no="9216735">Jo Smith

NMTOKENS Allows multiple NMTOKEN names separated by whitespace

NOTATION •Useful when text needs to be interpreted in a particular way. • The first character of a NOTATION name must be a letter, '_', or ':‘ Example: ]> Some VRML instructions

enumerated • make a choice between different attribute values. • first character of an Enumerated value must be a letter, digit, '.', '-', '_', or ':' Example 1: ]> This is an important task that must be completed This task can wait

Default value ]> This is an important task. This is by default a task that has a normal status.

Default value contd… ]> go to the bank pay the phone bill

CDATA Section • CDATA sections are used to display markup without the XML processor trying to interpret that markup. • They are particularly useful when you want to display sections of XML code. syntax:

CDATA Section ]> ]> ]]>

Predefined General Entity Predefined General Entities

How to Declare these entities

<



>



&



"



'



"kumar"

INTERNAL (PARSED) GENERAL ENTITY • Internal parsed entities generally reference text. Syntax: where:



entity value: any character that is not an '&', '%' or ' " ', ]> &js;

Related Documents

Dtd
November 2019 18
Dtd
October 2019 19
Dtd Tutorial
July 2020 8
Exploring The Xhtml Dtd
December 2019 16
Eis Model Dtd
November 2019 14