Presentation is loading. Please wait.

Presentation is loading. Please wait.

IS432: Semi-Structured Data Dr. Azeddine Chikh. 8. XML Relational Mapping.

Similar presentations


Presentation on theme: "IS432: Semi-Structured Data Dr. Azeddine Chikh. 8. XML Relational Mapping."— Presentation transcript:

1 IS432: Semi-Structured Data Dr. Azeddine Chikh

2 8. XML Relational Mapping

3 Introduction A common question in the XML community is how to map XML to databases. two mappings: – a table-based mapping – an object-relational (object-based) mapping. Both mappings model the data in XML documents rather than the documents themselves.

4 Introduction The table-based mapping can't handle mixed content at all, and the object-relational mapping of mixed content is extremely inefficient. Both mappings are commonly used as the basis for software that transfers data between XML documents and databases, especially relational databases. Both mappings are bidirectional. That is, they can be used to transfer data both from XML documents to the DB and from the DB to XML documents.

5 Table-based Mapping There is an obvious mapping between the following XML document and table: ccc Table A ddd ------- eee C D E --- --- ---......... fff ccc ddd eee ggg fff ggg hhh hhh.........

6 Table-based Mapping It views the document as a single table or a set of tables. The structure of the document must be either......... or

7 Table-based Mapping...............

8 Table-based Mapping The table-based mapping is commmonly used by middleware to transfer data between XML documents and relational databases. It is also used in some Web application servers to return result set data as XML.

9 Generating Schema 1.Generating Relational Database Schema from DTDs 2.Generating DTDs from Database Schema

10 Generating Relational Database Schema from DTDs Relational schemas are generated by reading through the DTD and processing each element type: – Complex element types generate class tables with primary key columns. – Simple element types are ignored except when processing content models.

11 Generating Relational Database Schema from DTDs The following example shows how this process works. Consider the following DTD:

12 Generating Relational Database Schema from DTDs DTD In the first step, we generate tables for complex element types and primary keys for these tables: ==> Table Order Column OrderPK ==> Table Item Column ItemPK ==> Table Part Column PartPK

13 Generating Relational Database Schema from DTDs DTD In the second step, we generate columns for references to simple element types: ==> Table Order - Column OrderPK Column OrderNum Column Date Column CustNum ==> Table Item - Column ItemPK Column ItemNum Column Quantity ==> Table Part - Column PartPK Column PartNum Column Price

14 Generating Relational Database Schema from DTDs DTD In the final step, we generate foreign keys for references to complex element types: ==> Table Order - Column OrderPK Column OrderNum Column Date Column CustNum ==> Table Item - Column ItemPK Column ItemNum Column Quantity Column OrderFK Column PartFK ==> Table Part - Column PartPK Column PartNum Column Price

15 Generating Relational Database Schema from DTDs A generated schema isn't going to be the same as a human would have written.

16 Generating DTDs from Database Schema DTDs are generated by starting from a single "root" table or set of root tables and processing each: Each root table generates an element type with element content in the form of a single sequence. Each data (non-key) column in the table generates an element type with PCDATA-only content and a reference in the sequence; nullable columns generate optional references.

17 Generating DTDs from Database Schema The following example shows how this process works. Consider the following database schema: Table Orders Column OrderNum Column Date Column CustNum Table Items Column OrderNum Column ItemNum Column Quantity Column PartNum Table Parts Column PartNum Column Price

18 Generating DTDs from Database Schema In our first step, we generate an element type for the root table (Orders): Table Orders ==> Column OrderNum Column Date Column CustNum Table Items Column OrderNum Column ItemNum Column Quantity Column PartNum Table Parts Column PartNum Column Price

19 Generating DTDs from Database Schema Next, we generate PCDATA-only elements for the data columns (Date and CustNum) and add references to these elements to the content model of the Orders element: Table Orders ==> Column OrderNum Column Date Column CustNum Table Items Column OrderNum Column ItemNum Column Quantity Column PartNum Table Parts Column PartNum Column Price

20 Generating DTDs from Database Schema Now we generate a PCDATA-only element for the primary key (OrderNum) and add a reference to it to the content model: Table Orders ==> Column OrderNum Column Date Column CustNum Table Items Column OrderNum Column ItemNum Column Quantity Column PartNum Table Parts Column PartNum Column Price

21 Generating DTDs from Database Schema And then add an element for the table (Items) to which the primary key is exported, as well as a reference to it in the content model: Table Orders Column OrderNum Column Date Column CustNum Table Items ==> Column OrderNum Column ItemNum Column Quantity Column PartNum Table Parts Column PartNum Column Price

22 Generating DTDs from Database Schema We process the data and primary key columns in the remote (Items) table in the same way: Table Orders Column OrderNum Column Date Column CustNum Table Items ==> Column OrderNum Column ItemNum Column Quantity Column PartNum Table Parts Column PartNum Column Price

23 Generating DTDs from Database Schema And then add an element for the table (Parts) to which the foreign key corresponds: Table Orders Column OrderNum Column Date Column CustNum Table Items Column OrderNum Column ItemNum Column Quantity Column PartNum Table Parts ==> Column PartNum Column Price

24 Generating DTDs from Database Schema Finally, we process the foreign key table (Parts): Table Orders Column OrderNum Column Date Column CustNum Table Items Column OrderNum Column ItemNum Column Quantity Column PartNum Table Parts ==> Column PartNum Column Price

25 Generating DTDs from Database Schema As was the case in the previous section, the generated DTD is not what a human would have created.


Download ppt "IS432: Semi-Structured Data Dr. Azeddine Chikh. 8. XML Relational Mapping."

Similar presentations


Ads by Google