120 likes | 444 Views
The One-to-many Relationship. A relationship in which one object can reference several instances of another. Learning Objectives. Learn different techniques of implementing one-to-many relationships in XML Create custom data types in an XML schema
E N D
The One-to-many Relationship A relationship in which one object can reference several instances of another.
Learning Objectives • Learn different techniques of implementing one-to-many relationships in XML • Create custom data types in an XML schema • Create empty elements with attributes in an XML document • Build XML stylesheets using HTML style tags
Implementing a One-to-ManyRelationship • Containment relationships • Example: <Team> <Name>Bulldogs</Name> <Player> <Name>Mike</Name> </Player> <Player> <Name>Vick</Name> </Player> </Team>
Implementing a One-to-ManyRelationship • Intra-document relationships • Example: <Teams> <Team id="d1"> <Name>Bulldogs</Name> </team> <Team id="d2"> <Name>Yellow Jackets</Name> </team> </teams> <Players> <Player TeamRef="d1"> <Name>Mike</Name> </Player> <Player TeamRef="d2"> <Name>Vick</Name> </Player> </Players>
Implementing a One-to-ManyRelationship • Inter-document relationships • Different tables may be located in different documents or files • Example: <Team id="d1"> <Name>Bulldogs</Name> </Team> <Team id="d2"> <Name>Yellow Jackets</Name> </Team> <Player> <Team href=";Team.xml#d1"/> <Name>Mike</Name> </Player> <Player> <Team href="Teams.xml#d2"/> <Name>Vick</Name> </Player>
XML Schema Data Types • Basic data types • i.e. integer, boolean, string, decimal • Additional types • i.e. year, month, time, date, anyURI • Custom data types • Created by the user to define specific fields/values • Custom Data Type Example
Regular Expression & Element Types • Perl’s regular expression language can be used to construct a pattern in defining an XML schema • Element Types • Element content • Root element; consists of elements only between tags • Mixed content element • Consists of text as well as other elements between tags • Single content element • Consists of only text between tags • Empty content element • Contains nothing between its opening and closing tags
Attributes • Same naming structure as elements • In single element, attributes’ names must be unique • May not contain the “<“ symbol and the character string “<” can be used to represent it • Each attribute must have a name and a value • <hotelPicture filename="pook_hill_lodge.jpg" size="80" value="Image of Pook's Hill Lodge" imageURL="http://www.global-travel.co.uk/pook1.htm"/> • If quotes are used to enclose to enclose the string, they must differ from the quotes used to enclose the value. • <name familiar=“‘Jack’”>John Smith</name>
XSL: Stylesheets • Using tables for layout • Also set background color, font-size, font-weight, and alignment using the style tag in HTML • Stylesheet
Summary • Ways to implement a one-to-many relationship • Containment • Intra-document • Inter-document • Custom data types • Use built-in data types and apply restrictions, facets, or specific patterns • Empty element • Contains no text but may contain attributes for better element definition • Presentation layout with stylesheets • HTML style tags and table layout
Exercise: Movie Database • Create an XML schema to depict a relationship between movie genres, movies, and actors/actresses • Choose two genres (drama, horror, action, etc.), two movies in each, and several actors/actresses from each. • Using the schema, create a document and populate it with the chosen information as well as additional actor/actress data including social security number in regex. • Create an XML stylesheet to present the data in table form for easier readability