xml many-to-many relationship january 30, 2006. learning objectives ● create a schema for a data...

18

Click here to load reader

Upload: kerry-mccarthy

Post on 05-Jan-2016

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: XML Many-to-Many Relationship January 30, 2006. Learning Objectives ● Create a schema for a data model containing a many:many relationship ● Understand

XML

Many-to-ManyRelationship

January 30, 2006

Page 2: XML Many-to-Many Relationship January 30, 2006. Learning Objectives ● Create a schema for a data model containing a many:many relationship ● Understand

Learning Objectives

● Create a schema for a data model containing a many:many relationship

● Understand the purpose of and how to implement an XML include

● Define the format of displayed numeric values using an XML numeric function

● Define numeric elements using more specific data types

Page 3: XML Many-to-Many Relationship January 30, 2006. Learning Objectives ● Create a schema for a data model containing a many:many relationship ● Understand

M:M Data Model

A hotel can have many amenities, and an amenity can be at many hotels.

Page 4: XML Many-to-Many Relationship January 30, 2006. Learning Objectives ● Create a schema for a data model containing a many:many relationship ● Understand

M:M Relationships in XML:Problem

● Many-to-many relationship is not supported directly by XML.

● Each element may only have a single parent element.

Page 5: XML Many-to-Many Relationship January 30, 2006. Learning Objectives ● Create a schema for a data model containing a many:many relationship ● Understand

M:M Relationships in XML:Solutions

● Create XML documents that eliminate the need for a many-to-many relationship.– Create a separate XML doc for each entity.– Eliminate the need for a many-to-many

relationship by creating two schemas.● Represent the many-to-many relationship

using unique identifiers.● Discard the information that requires the

many-to-many relationship.

Page 6: XML Many-to-Many Relationship January 30, 2006. Learning Objectives ● Create a schema for a data model containing a many:many relationship ● Understand

Two 1:M Relationships

● How do you link schemas?– <include> element:<xsd:include schemaLocation="amenity.xsd"/>

Page 7: XML Many-to-Many Relationship January 30, 2006. Learning Objectives ● Create a schema for a data model containing a many:many relationship ● Understand

Multiple Schemas:Advantages

● Ease of schema maintenance

● Improved schema readability

● Commonly occurring elements can be reused by other schemas.

Page 8: XML Many-to-Many Relationship January 30, 2006. Learning Objectives ● Create a schema for a data model containing a many:many relationship ● Understand

Exercise 1: <include>

1) Create a separate schema.2) Link schemas with <include> element.

Page 9: XML Many-to-Many Relationship January 30, 2006. Learning Objectives ● Create a schema for a data model containing a many:many relationship ● Understand

Data Types for Schemas

● Previous chapters: – year– month– time– anyURI– date

Page 10: XML Many-to-Many Relationship January 30, 2006. Learning Objectives ● Create a schema for a data model containing a many:many relationship ● Understand

More Schema Data Types

Name Description

byte A signed 8-bit integer

int A signed 32-bit integer

long A signed 64-bit integer

negativeInteger An integer containing only negative values (..., -2, -1)

nonNegativeInteger An integer containing only non-negative values (0, 1, 2, ...)

nonPositiveInteger An integer containing only non-positive values (..., -2, -1, 0)

positiveInteger An integer containing only positive values (1, 2, ...)

short A signed 16-bit integer

unsignedLong An unsigned 64-bit integer

unsignedInt An unsigned 32-bit integer

unsignedShort An unsigned 16-bit integer

unsignedByte An unsigned 8-bit integer

http://www.xml.dvint.com/docs/SchemaDataTypesQR-2.pdf

Page 11: XML Many-to-Many Relationship January 30, 2006. Learning Objectives ● Create a schema for a data model containing a many:many relationship ● Understand

Exercise 2: Data Types

● Use data type “positiveInteger” to describe data for:– City population– Hotel lower price– Hotel upper price

Page 12: XML Many-to-Many Relationship January 30, 2006. Learning Objectives ● Create a schema for a data model containing a many:many relationship ● Understand

XSLT Functions

● Manipulate or format numeric data– Chapter 3, 1:M relationship:

<xsl:value-of-select = “count(hotel)” />displays number of hotels within a city

– Chapter 5, M:M relationship:format-number() functionconverts a numeric value into a string using specified patterns

Page 13: XML Many-to-Many Relationship January 30, 2006. Learning Objectives ● Create a schema for a data model containing a many:many relationship ● Understand

XSLT Functions

● Format-number (number, pattern)– Number is the numeric value to be formatted– Pattern is a string that lays out the general

representation of a number. Each character in the string represents either a digit from number or some special punctuation such as a comma or minus sign.

Page 14: XML Many-to-Many Relationship January 30, 2006. Learning Objectives ● Create a schema for a data model containing a many:many relationship ● Understand

XSLT Functions

Character Description

0 A digit

# A digit, zero shows as absent

. (period) placeholder for decimal separator

, Placeholder for grouping separator

; Separate formats

- Default prefix for negative

% Multiply by 100 and show as a percentage

X Any other characters can be used in the prefix or suffix

' Used to quote special characters in a prefix or suffix

Page 15: XML Many-to-Many Relationship January 30, 2006. Learning Objectives ● Create a schema for a data model containing a many:many relationship ● Understand

Other XSLT Functions

Name Description

Ceiling() Returns the smallest integer that is not less than the numberargument

Floor() Returns the largest integer that is not greater than the numberargument

Number() Converts the value argument to a number

Round() Rounds the number argument to the nearest integer

Sum() Returns the total value of a set of numeric values in a node-set

Position() Returns the position of the current context node in the currentcontext node-set

Last() Returns the index number of the last node in the context

Page 16: XML Many-to-Many Relationship January 30, 2006. Learning Objectives ● Create a schema for a data model containing a many:many relationship ● Understand

Exercise 3: XSLT Functions

1.Use format-number() function to display population to show digits grouped by three's, separated by a comma.

2.Use position() and last() functions to separate hotel amenities with a comma.

Page 17: XML Many-to-Many Relationship January 30, 2006. Learning Objectives ● Create a schema for a data model containing a many:many relationship ● Understand

Summary

● To implement a m:m relationship in XML, it is necessary to break the relationship into two one-to-many type relationships.

● A schema designer may find it necessary to break the schema into separate files and link them using an include statement.

● Numeric elements can be more specifically described using data types that define the number type.

● Additional numeric functions can be used in the XML style sheet to manipulate or format numeric data.

Page 18: XML Many-to-Many Relationship January 30, 2006. Learning Objectives ● Create a schema for a data model containing a many:many relationship ● Understand

M:M Chapter Exercise

1. Create two XML schemas to describe the illustrated data model. Include all of the attributes listed in the data model.

2. Create an XML document that includes at least two movies and two cast members per movie.

3. Create an XML style sheet to present the information in HTML format.