73bce859195acd88114ff5c6089ea53f.ppt
- Количество слайдов: 26
XML and The Relational Data Model <author> By: Soid Quintero </author>
Overview Define XML model vs. relational model XML Documents Xpath XQuery Going from XML to the relational model
What is XML? XML stands for Extensible Markup Language It is a metalanguage used to represent and manipulate data elements Similar to HTML in structure, but XML is concerned with the description and representation of data, rather than with the way it is displayed. XML is derived from Standard Generalized Markup Language (SGML) XML data is used to create XML documents.
Why XML for databases? One of the main reasons that XML was developed was to allow the exchange of semi-structured documents, like invoices, order forms, applications, etc. , over the internet. Using a database system to store XML documents allows users to be able to better access information. XML is also very flexible Data is maintained in a self-describing format to accommodate a variety of ever-evolving business needs.
What is an XML Database? Simply a database that stored XML Documents There are two major types of XML databases: XML-enabled. These map all XML to a traditional database (such as a database), accepting XML as input and rendering XML as output. Native XML (NXD) The internal model of such databases depends on XML and uses XML documents as the fundamental unit of storage.
XML Model VS. Relational Model? XML data is hierarchical XML data is self-describing XML data has inherent ordering An XML database contains collections relational data is represented in a model of logical relationships. relational data is not selfdescribing. Relational data does not have inherent ordering. A relational database contains tables
Relational Model Order of rows is not guaranteed unless the ORDER clause is used in one or more columns Relations (tables) Data is represented in n-ary relations. Has a domain that represents a set of values Attributes (columns) Strict schema Restrictive The strict schema insures data integrity
XML Model The XML Model is hierarchical format Data is represented in trees structures There's nodes Relationships between the node The schema provides flexibility Easily modified format
multiple elements represented in a hierarchy, including a root“Comments” element and one or more individual “Comment” elements pertaining to a given item.
XML Document Rules XML documents must be well formated, meaning that every opening tag needs a closing tag (ex. <Student> </Student> ) It allows users to define their own tags (unlike HTML) The XML tags need to be properly nested. The XML and xml tags are reserved for XML tags only. You can use <-- XXX --> symbols for comments XML is case sensitive so, <Student> is not the same as <STUDENT> Two types of XML documents commonly used, Document Type Definition (DTD) or an XML Schema Definitions (XSD)
What is a Document Type Definition? DTDs can be declared inline of the XML code or can reference an external file It provides the composition of the database's logical model and defines the syntax rules or valid tags for each type of XML document. A DTD is a file that has a. dtd extension. This file describes XML elements. Example of a DTD on next slide. . . .
Inline DTD message. xml <? xml version="1. 0"? > <!DOCTYPE message [ <!ELEMENT message (to, from, subject, text)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT subject (#PCDATA)> <!ELEMENT text (#PCDATA)> ]> <message> <to>Dave</to> <from>Susan</from> <subject>Reminder</subject> <text>Don't forget to buy milk on the way home. </text> </message> External DTD message. xml <? xml version="1. 0"? > <!DOCTYPE message SYSTEM "message. dtd"> <message> <to>Dave</to> <from>Susan</from> <subject>Reminder</subject> <text>Don't forget to buy milk on the way home. </text> </message> message. dtd <? xml version="1. 0"? > <!ELEMENT message (to, from, subject, text)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT subject (#PCDATA)> <!ELEMENT text (#PCDATA)>
What is an XML Schema Definition? The XML Schema is an advance definition language that is used to describe the structure (elements, data types, relationships types, ranges, and default values) It is an alternative to DTD Since data types are allowed data validation is possible and easier to do. A XSD file has a. xsd extension Example of a XSD on next slide. . . .
<? xml version="1. 0"? > <xs: schema xmlns: xs="http: //www. w 3. org/2001/XMLSchema" target. Namespace="http: //www. w 3 schools. com" xmlns="http: //www. w 3 schools. com" element. Form. Default="qualified"> <xs: element name="note"> <xs: complex. Type> <xs: sequence> <xs: element name="to" type="xs: string"/> <xs: element name="from" type="xs: string"/> <xs: element name="heading" type="xs: string"/> <xs: element name="body" type="xs: string"/> </xs: sequence> </xs: complex. Type> </xs: element> </xs: schema>
How do you access XML data? There are several languages used to access XML data from XML Documents, some are: XPath XQuery XML-QL XQL etc. .
XPath Xpath is a language used to extract parts of an XML document. XPath uses path expressions to navigate in XML documents Xpath has 7 kinds of nodes: Element Attribute Text Namespace Processing-Instruction Comment Document(root)
Examples of XPath <? xml version="1. 0" encoding="ISO-8859 -1"? > <bookstore> Attribute node Document node <book> <title lang="en">Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29. 99</price> </book> Element node </bookstore> Example of an XPath expressions: /bookstore Will select the root element bookstore /bookstore/book Selects all book elements that are children of bookstore
XQuery is a language for finding and extracting elements and attributes from XML documents. XQuery for XML is like SQL for databases XQuery is built on XPath expressions XQuery is supported by all the major database engines (IBM, Oracle, Microsoft, etc. )
Example of XQuery <? xml version="1. 0" encoding="ISO-88591"? > <bookstore> <book category="COOKING"> <title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30. 00</price> </bookstore> Example of an XQuery expressions: doc("books. xml")/bookstore/book/title Will return: <title lang="en">Everyday Italian</title>
The XQuery FLWOR for: Iterates through a sequence, bind variable to items let: binds a variable to a sequence where: eliminates items of the iteration order by: reorders items of the iteration return: constructs query results Example of a XQuery expression: for $x in doc("books. xml")/bookstore/book where $x/price>29 return $x/title Will return: <title lang="en">Everyday Italian</title>
Going from XML Model to Relational Model XML documents can be decomposed into a relational table. Those decomposed XML documents can be made into relational tables and published to an XML document( they might differ from the original) During the decomposing process, the XML document loses most of it structure in order to map into the relational table; not all the tags are stored in the relational tables.
Example of an XML document <ORDER> <ORDER_ID=’ 83492’ CUST_ID=’ 93457’> <ITEM> <PROD_ID>94872</PROD_ID> <PROD_NAME>PEN</PROD_NAME> <PRICE>19. 95</PRICE> <QUANTITY>30</QUANTITY> </ITEM> <PROD_ID>94866</PROD_ID> <PROD_NAME>BINDER</PROD_NAME> <PRICE>7. 95</PRICE> <QUANTITY>26</QUANTITY> </ITEM> <PROD_ID>92219</PROD_ID> <PROD_NAME>LABELS</PROD_NAME> <PRICE>12. 95</PRICE> <QUANTITY>250</QUANTITY> </ITEM> </ORDER> XML document decomposed into a relation Order Items
Another Example. . . Sales Order <Sales. Order Number="123"> <Order. Date>2003 -07 -28</Order. Date> <Customer. Number>456</Customer. Number> <Item Number="1"> <Part. Number>XY 47</Part. Number> <Quantity>14</Quantity> <Price>16. 80</Price> </Item> <Item Number="2"> <Part. Number>B 987</Part. Number> <Quantity>6</Quantity> <Price>2. 34</Price> </Item> </Sales. Order> Items table
Hybrid DBMS There are DBMS that allow the use of both the relational model and the XML data model, a so call “Hybrid” model. An example of such a DBMS is IBMs DB 2. Architecture of DB 2
References (1) “Comparison of XML Model and the Relational Model. ” DB 2 Version 9 for Linux, UNIX, and Windows. 10 April. 2007 <http: //publib. boulder. ibm. com/infocenter/db 2 luw/v 9/topic/com. ibm. db 2. udb. apdv. embed. doc/c 0023811. htm>. (2) W 3 Schools. <http: //www. w 3 schools. com/xpath/default. asp> (3) W 3 Schools. <http: //www. w 3 schools. com/xquery/default. asp> (4) Coss Rafael. “DBS 9 pure. XML”. IMSS_DB 2 pure. XML_v 3. ppt. (5) Coss, Rafael. “XML L 2 Skills Transfer - template”. Jan 14, 2005. XML_L 2~1. ppt (6) Bourret, Ronald. XML “Database. Products“. Ronald Bourret Consulting, writing, and research in XML and database. March 13, 2007. <http: //www. rpbourret. com/xml/XMLDatabase. Prods. htm#xmlanddatabases>
(7) W 3 Schools. <http: //www. w 3 schools. com/dtd/default. asp> (8)Steegmans, Bart. Bourret, Ronald. Olivier, Guvennet. ” XML for DB 2 Information Integration”. IBM Redbooks. <http: //www. redbooks. ibm. com/redbooks/SG 246994/wwhelp/wwhimpl/java/ht ml/wwhelp. htm>
73bce859195acd88114ff5c6089ea53f.ppt