data type definition

24
Data Type Definition Data Type Definition Chao-Hsien Chu, Ph.D. School of Information Sciences and Technology The Pennsylvania State University Entity Notations Elements Attributes

Upload: jelani-dixon

Post on 01-Jan-2016

34 views

Category:

Documents


3 download

DESCRIPTION

Data Type Definition. Chao-Hsien Chu, Ph.D. School of Information Sciences and Technology The Pennsylvania State University. Elements Attributes. Entity Notations. Components of XML Systems. XSL Java. XML Document ( Contents ). Well-Formed (Syntax). XML Application. XML Parser - PowerPoint PPT Presentation

TRANSCRIPT

Data Type DefinitionData Type Definition

Chao-Hsien Chu, Ph.D.School of Information Sciences and Technology

The Pennsylvania State University

EntityNotations

Elemen

ts

Attribu

tes

Components of XML SystemsComponents of XML Systems

XMLParser

(Processor)

XMLApplication

XMLDocument(Contents)

DTD

Well-Formed(Syntax)

Validate(Structure)

Schema

XSLJava. . .

Database Database

ASPPerl. . .

(Rules)

IssueWarning/Stop

Processing

(optional)

How a Parser Interprets XML - ValidateHow a Parser Interprets XML - Validate

XMLDocument

Data TypeDefinition

IssueWarning/Stop

Processing

FurtherProcessing

WellFormed? DTD?

Valid?

no

no

no

yes

yes

yes

The Panoramic Perspective of XMLThe Panoramic Perspective of XML

XMLDocument

Prolog

Doc. TypeDeclaration

RootElement

Comments

ProcessingInstructions

Comments

ProcessingInstructions

Comments

ProcessingInstructions

EntityReferences

CDATASections

Elements PCDATA

Attributes

EntityReferences

CDATA,Entities, ID,..

Doc TypeDefinitions

ElementDeclaration

AttributeDeclaration

EntityDeclaration

NotationsDeclaration

: Optional

Purposes of DTDPurposes of DTD

What elements should be presented?

How many of each element were required?

What kind of element content was permitted?

In what order the elements should appear?

DTD is used to specify which elements are allowed where in the document. An DTD file provides the following information:

Components of DTDComponents of DTD

Comments

Element Type Declarations

Attribute List Declarations

Entity Declarations

Notations Declarations

DTD DeclarationDTD Declaration

DTD is optional. Declaration is provided in the XML document.

External: <?xml version = "1.0" standalone = "no"?> <!DOCTYPE Root Element SYSTEM “xxx.dtd">

Internal: <?xml version = "1.0" standalone = “yes"?> <!DOCTYPE Root Element [ Contents of DTD ]>

CommentsComments

A place to write a note for reminding, simple documentation, or commenting out codes for debugging, etc., which will not be seen by the end users.

<!-- This is a comment area

--> You can use any character inside the comment

area except “--” itself

There is no limitation on the length of the comment area.

Tree Diagram of Address DocumentTree Diagram of Address Document

Address_Book

Contact*

IDName E-mail Phone Address

ZipStateCityStreet

Root Element

Example of DTD FileExample of DTD File

<!ELEMENT Address_Book (Contact)*> <!ELEMENT Contact (Name,ID,EMAIL,Phone,Address)> <!ELEMENT Name (#PCDATA) > <!ELEMENT ID (#PCDATA) > <!ELEMENT EMAIL (#PCDATA) > <!ELEMENT Phone (#PCDATA) > <!ELEMENT Address (Street,City,State, ZIP) > <!ELEMENT Street (#PCDATA) > <!ELEMENT City (#PCDATA) > <!ELEMENT State (#PCDATA) > <!ELEMENT ZIP (#PCDATA) >

Root Element

Tree Diagram for RecipeTree Diagram for Recipe

Recipe

Name

Description?

Ingredients?

Instructions?

Ingredient*

Step+

Qty

Item

unit

optional

isVegetarian

Example of DTD FileExample of DTD File

<!ELEMENT Recipe (Name, Description?, Ingredients?, Instructions?)>

<!ELEMENT Name (#PCDATA)>

<!ELEMENT Description (#PCDATA)>

<!ELEMENT Ingredients (Ingredient)*>

<!ELEMENT Ingredient (Qty, Item)>

<!ELEMENT Qty (#PCDATA)>

<!ATTLIST Qty unit CDATA #REQUIRED>

<!ELEMENT Item (#PCDATA)>

<!ATTLIST Item optional CDATA "0" isVegetarian CDATA "true">

<!ELEMENT Instructions (Step)+>

Element Type Declarations

Attribute List Declarations

Element Type DeclarationsElement Type Declarations

Element Name. Content Model – Type of information The attributes associated with it.

Syntax:

<!ELEMENT element_name (content_model)>

Example:

<!ELEMENT First_Name (#PCDATA)>

Content ModelContent Model

Subelements – list of subelements<!ELEMENT name (first_name, last_name)>

PCDATA – Text only (zero or more characters)<!ELEMENT element_name (#PCDATA)>

EMPTY – No content<!ELEMENT element_name EMPTY>

ANY – an undefined mixture of elements that have been declared in the DTD as well as character data.<!ELEMENT element_name ANY>

Occurrences of SubelementsOccurrences of Subelements

none: once and only once.

+: at least once or more.

?: zero (never) or once.

*: optional; zero or more.

|: either. only one occurrence allowed.

Common Errors in ETDCommon Errors in ETD

The element type declaration must be in CAPITALS.

The order of elements declared makes a big difference.

Did not use a right “validator”.

Attribute List DeclarationsAttribute List Declarations

The element to which the attribute is associated. The name of the attribute. The type of the attribute. The default value. Syntax:

<!ATTLIST element_nameattribute_name

attribute_typeattribute_defaults

>

Attribute TypesAttribute Types

String (CDATA)

Enumerated | (one of specified values)

ENTITY

ENTITIES

ID

IDREF

IDREFS

NMTOLKEN

NMTOLKENS

NOTATION

Attribute DefaultAttribute Default

Required – must supply a value.

Implied – The value is optional.

Fixed – fixed set of attributes. The values are included in the declaration itself.

Supplied – the DTD will supply the default value if it is not supply in the XML document.

Entities DeclarationEntities Declaration

Entities are used to define shortcuts to commonly used text.

Internal Entity – the entity was declared within the XML document.

External Entity – the entity was declared in a DTD file.

Internal EntityInternal Entity

<?xml version=“1.0”?>

<!DOCTYPE Company [<!ENTITY Company “XML Inc.”>]>

<Company>

<Name> &Company; </Name>

<Address>Singapore</Address>

</Company>

External EntityExternal Entity

Store the following statement in a file named “Entity.dtd”:

<!ENTITY Company “XML Inc.”>

Example:

<?xml version=“1.0”?>

<!DOCTYPE Company SYSTEM “Entity.dtd”>

<Company>

<Name> &Company; </Name>

<Address>Singapore</Address>

</Company>

Thank You?

Any Question?

Programs/SystemsPrograms/Systems

http://www.jclark.com/xml/ http://www.jclark.com/xml/xt.html Microsoft XML Notepad