XML Structures For Existing Databases Ref: 106.ibm.com/developerworks/xml/library/x-struct/

Slides:



Advertisements
Similar presentations
Oracle Object-Relational Model. - Structures : tables, views, indexes, etc. - Operations : actions that manipulate data stored in structures - Integrity.
Advertisements

Chapter 10: Designing Databases
An Introduction to XML Based on the W3C XML Recommendations.
1 DTD (Document Type Definition) Imposing Structure on XML Documents (W3Schools on DTDs)W3Schools on DTDs.
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.
DTDs : definitions. Defining Elements PCDATA: Parsed character data i.e., any characters without further XML structure.
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.
Introduction to XLink Transparency No. 1 XML Information Set W3C Recommendation 24 October 2001 (1stEdition) 4 February 2004 (2ndEdition) Cheng-Chia Chen.
Fundamentals, Design, and Implementation, 9/e Chapter 5 Database Design.
A Technical Introduction to XML Transparency No. 1 XML quick References.
 2002 Prentice Hall, Inc. All rights reserved. ISQA 407 XML/WML Winter 2002 Dr. Sergio Davalos.
TU/e eindhoven university of technology / faculty of mathematics and informatics Exporting Databases in XML DTD A Conceptual and Generic Approach Philippe.
Data Modelling. EAR model This modelling language allows a very small vocabulary: Just as English has nouns, verbs, adjectives, pronouns.., EAR models.
CS424 PK, FK, FD Normalization Primary and Foreign Keys Primary and foreign keys are the most basic components on which relational theory is based. Primary.
Database – Part 2a Dr. V.T. Raja Oregon State University.
1 Print your own copy If you bring it along, hand in with your exam script Do not write anything extra or you will be penalized Student Name: Student Number:
XML Verification Well-formed XML document  conforms to basic XML syntax  contains only built-in character entities Validated XML document  conforms.
VALIDATING AN XML DOCUMENT
1 Advanced Topics XML and Databases. 2 XML u Overview u Structure of XML Data –XML Document Type Definition DTD –Namespaces –XML Schema u Query and Transformation.
Tutorial 3: XML Creating a Valid XML Document. 2 Creating a Valid Document You validate documents to make certain necessary elements are never omitted.
XP New Perspectives on XML Tutorial 3 1 DTD Tutorial – Carey ISBN
XML-to-Relational Schema Mapping Algorithm ODTDMap Speaker: Artem Chebotko* Wayne State University Joint work with Mustafa Atay,
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.
Lecture 6 of Advanced Databases XML Schema, Querying & Transformation Instructor: Mr.Ahmed Al Astal.
Chapter 10: XML.
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.
1 XML Schemas. 2 Useful Links Schema tutorial links:
Dr. Azeddine Chikh IS446: Internet Software Development.
MIS 385/MBA 664 Systems Implementation with DBMS/ Database Management Dave Salisbury ( )
XML Syntax - Writing XML and Designing DTD's
XMLI Structure of XML Data Structure of XML Data XML Document Schema XML Document Schema XPATH XPATH.
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.
XML (2) DTD Sungchul Hong.
Processing of structured documents Spring 2002, Part 2 Helena Ahonen-Myka.
XML. 2 XML- Some Links XML Tutorials – Some Links me=htmlhttp://
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.
Of 33 lecture 3: xml and xml schema. of 33 XML, RDF, RDF Schema overview XML – simple introduction and XML Schema RDF – basics, language RDF Schema –
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation Identity Constraints.
XML and DTD Please you speaker notes for additional information!
XML Validation I DTDs Robin Burke ECT 360 Winter 2004.
1/11 ITApplications XML Module Session 3: Document Type Definition (DTD) Part 1.
CSE3201 Information Retrieval Systems DTD Document Type Definition.
Sheet 1XML Technology in E-Commerce 2001Lecture 2 XML Technology in E-Commerce Lecture 2 Logical and Physical Structure, Validity, DTD, XML Schema.
XML – A Quick Introduction Kerry Raymond (stolen from others)
1 Chapter2. XML Structures for Existing Databases Database 연구실 석사 1 학기 편선경.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan Lecture-03 Introduction –Data Models Lectured by, Jesmin Akhter.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation Mapping RDB Schema to.
Management of XML and Semistructured Data Lecture 10: Schemas Monday, April 30, 2001.
Beginning XML 3 rd Edition. Chapter 4: Document Type Definitions.
INFSY 547: WEB-Based Technologies Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
SNU OOPSLA Lab. Logical structure © copyright 2001 SNU OOPSLA Lab.
Copyright 2000, 2001, Ronald Bourret, Mapping DTDs to Databases Ronald Bourret
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2.
XML Validation II Schemas Robin Burke ECT 360. Outline Namespaces Documents  Data types XML Schemas Elements Attributes Derived data types RELAX NG.
QUALITY CONTROL WITH SCHEMAS CSC1310 Fall BASIS CONCEPTS SchemaSchema is a pass-or-fail test for document Schema is a minimum set of requirements.
Document Type Definition (DTD) Eugenia Fernandez IUPUI.
* Database is a group of related objects * Objects can be Tables, Forms, Queries or Reports * All data reside in Tables * A Row in a Table is a record.
XML Validation II Advanced DTDs + Schemas Robin Burke ECT 360.
XML Validation. a simple element containing text attribute; attributes provide additional information about an element and consist of a name value pair;
Tutorial on E-R Diagrams 1.Learn basic terminology and symbols –See next four slides; refer to as needed in steps 2-4 below 2.Learn the basics of E-R diagramming.
Copyrighted material John Tullis 3/18/2016 page 1 04/29/00 XML Part 4 John Tullis DePaul Instructor
Chapter 5 Database Design
Chapter 1 XML Design for Data
Managing XML and Semistructured Data
XML Data DTDs, IDs & IDREFs.
New Perspectives on XML
DTD (Document Type Definition)
Presentation transcript:

XML Structures For Existing Databases Ref: ibm.com/developerworks/xml/library/x-struct/

2 XML schema Validator The Sun Multi-Schema XML Validator (MSV) is a Java[tm] technology tool to validate XML documents against several kinds of XML schemata: download: chema/ chema/

3 Document Type Definitions DTDs are associated with the entire element tree via the document element.

4 Writing DTDs Example1.dtd Example1.xml XML How to write DTD

5 Validating Sun Validator Invoking the Validator: java -jar C:\pathName\msv.jar Example1.dtd Example2.xml Output: start parsing a grammar. validating Example1.xml the document is valid.

6 ID Attribute Type Attributes using the ID type serve as unique identifiers for a given instance of an element. The value of an ID attribute must be a valid XML name, unique within a document and use the #IMPLIED or #REQUIRED default value. #IMPLIED: No default value. The attribute is optional. #REQUIRED: The attribute must appear in every element type. #FIXED: Attributes may be optional, but when present are constrained to the given value. There may only be one ID attribute for one element type.

7 Example 2 Two One

8 Example 3 <!ATTLIST Order OrderId ID #REQUIRED > <!ATTLIST Item ItemId ID #REQUIRED > Item Item Item Item

9 Example 4 <!ATTLIST Order OrderId ID #REQUIRED > <!ATTLIST Item ItemId ID #REQUIRED Manf IDREF #REQUIRED > Item1

10 Example 5 <!ATTLIST Order OrderId ID #REQUIRED > <!ATTLIST Item ItemId %ID_Req; Manf IDREF #REQUIRED > Item1 &Greetings ;

11 Modeling Relationships Primary Keys: Invoice: invoiceId LineItem: lineItemId Foreign Keys: invoiceId in LineItem

12 Modeling Relationships One-to-one and one to many relationships are best represented by containment. In the following DTD, mostly attributes are used to represent the information in LineItem and Invoice. <!ATTLIST Invoice orderDate CDATA #REQUIRED customerId CDATA #REQUIRED> <!ATTLIST LineItem itemDesc CDATA #REQUIRED price CDATA #REQUIRED quantity CDATA #REQUIRED >

13 Example

14 Modeling Relationships Many to many relationships can be represented using pointers, that is ID/IDREF pairs. Using containment in this situation will result in redundancy of information Example: <!ATTLIST Invoice orderDate CDATA #REQUIRED customerId CDATA #REQUIRED> <!ATTLIST LineItem itemIDREF IDREF #REQUIRED price CDATA #REQUIRED quantity CDATA #REQUIRED > <!ATTLIST Item itemId ID #REQUIRED itemName CDATA #REQUIRED itemDesc CDATA #REQUIRED >

15 XML Design For Data Some Issues To Consider Establish the scope of the document Identify the structures to model Identify the relationships between entities Identify data points that need to be associated with each structure

16 XML Design For Data Some Issues To Consider Example: Let us take two purchase orders and model them in XML. Books, Inc Purchase Order Order date: 6/25/2002 Shipping Date:6/27/2002 Customer: Mary Jones 500 Alameda Santa Clara, Santa Clara, CA Shipping Co:UPS Item No (ISBN)Descriptionquantitypricetotal Q1234Cosmos Q555XML Total$100.00

17 XML Design For Data Some Issues To Consider Books, Inc Purchase Order Order date: 7/28/2002 Shipping Date:7/30/2002 Customer: John Smith 555 Spring Ct Santa Clara, Santa Clara, CA Shipping Co:fedex Item No (ISBN)Descriptionquantitypricetotal Q333Java Q555XML Total$175.00

18 Establish the scope: –One XML document per PurchaseOrder –One XML document to represent a number of PurchaseOrders.

19 Identify the Structures to model Orders –PurchaseOrders –Customer –Item –LineItem

20

21 Creating The XML DTD Start With the Structures and establish the Elements

22 Add the Data points to the Elements We will use attributes to represent the data points <!ATTLIST Orders StartDateCDATA #REQUIRED EndDateCDATA#REQUIRED …. …. …. ….

23 Model the relationships Use containment whenever possible. Relationships: –Each Orders contains many PurchaseOrders. –Each PurchaseOrder has one Customer. –Each Customer may be associated with more than one PurchaseOrder. –Each LineItem has one Item. –Each Item may be in more than one LineItem

24 Each Orders contains many PurchaseOrders. Each PurchaseOrder contains many LineItems <!ATTLIST Orders StartDateCDATA #REQUIRED EndDateCDATA#REQUIRED …. …. …. ….

25 Modeling Relationships Modeling Relationships: Each PurchaseOrder has one Customer. Each Customer may be associated with more than one PurchaseOrder. Each LineItem has one Item. Each Item may be in more than one LineItem –To avoid the repetition of data for Customer and Item, we will use ID/IDREF to represent the one to many relationship. –The elements Customer and Item are promoted to the document scope

26 … <!ATTLIST PurchaseOrder orderDateCDATA#REQUIRED shippingDate CDATA#REQUIRED shippingCo(fedex | ups) #REQUIRED customerIDREFIDREF#REQUIRED …. <!ATTLIST Customer customerId ID #REQUIRED name CDATA #REQUIRED …

27 XML Structures For Existing Databases Migrating a Database To XML Scoping the XML Document Creating the Root Element Model the tables Model the non-foreign key values Adding ID attributes Handling Foreign Keys Adding the Relationships

28 Scoping the XML Document Choose the data to include in the XML document – Based on the business requirements the XML document will be fulfilling, decide which tables and columns will need to be included in the xml documents.

29 Creating The Root Element Create a Root Element Create a root element for the document. Declare any attributes of that element that are required to hold additional semantic information.

30 Model the tables Content tables: Contain a set of records. Eg: Customer information Lookup tables: Contain a list of ID-description pairs that are used to further classify information. Eg: Shipping Company Relation tables: Express many to many relationships as separate tables. These will be treated as content tables.

31 Content Tables Create an element in the DTD for each content table. Model the Non-foreign key values: As Attributes: As attributes in the ATTLIST associated with ach element; each attribute should have a type, CDATA and if it cannot take nulls in the database should include #REQUIRED; Otherwise, should be #IMPLIED. As Elements: If the attribute in database allows nulls, use ? as suffix; otherwise, use no suffix.

32 Adding ID attributes Add an ID attribute to each of the Elements (with the exception of root element). Use the element name followed by ID for the name of the new attribute, watching for name collisions. Note that a unique ID (unique across all elements in the document) will need to be created for each of the instance of an element. If there are row-based primary keys, use them by prefixing them with the table name.

33 Handling Foreign Keys Foreign keys serve as glue to connect the different tables in a database. In XML, relationships between elements can be represented –using containment (via nesting). –Using ID/IDREF pairs

34 Modeling Lookup Tables For each foreign key that we have chosen to include in our XML structures that references a lookup table: –Create an attribute on the element representing the table in which the foreign key is found. –Give the attribute the same name as the table referenced by foreign key. –Make the attribute of the enumerated list type. –Example: <!ATTLIST PurchaseOrder shippingCo(fedex | ups) #REQUIRED

35 Add Element content to the Root Element Add a child element or elements to the allowable content of the root element for each table that models the content information in the document.

36 Modeling the relationships Walk the relationships between tables to add ID/IDREF where applicable. We walk the relationships in the direction that makes the most business sense, for example, from PurchaseOrder to LineItem. If the relationship is 1 to 1 or 1 to n, in the direction that is being navigated, and no other relationship leads to the child within the selected subset, then add the child element as element content of the parent element with the appropriate cardinality.

37 Many-to-one or multiple-parent relationships: Identify each relationship that is many-to-one in the direction we have defined it, or whose child is a child in more than one relationship we have defined. For each of these relationships, add an IDREF or IDREFS attribute to the element on the parent side of the relationship, which points to the ID of the element on the child side of the relationship.

38 Add missing elements to the root element: For any element that is pointed to in the structure so far, add that element as allowable element content of the root element. Discard unreferenced ID attributes: Remove unwanted ID attributes. Remove ID attributes that are not referenced by IDREF or IDREFS attributes elsewhere in the XML structures.