Presentation is loading. Please wait.

Presentation is loading. Please wait.

XML and The Relational Data Model

Similar presentations


Presentation on theme: "XML and The Relational Data Model"— Presentation transcript:

1 XML and The Relational Data Model
<author> By: Soid Quintero </author>

2 Overview Define XML XML model vs. relational model XML Documents Xpath
XQuery Going from XML to the relational model

3 What is XML? Include and example of an XML document
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. Include and example of an XML document subset of SGML, SGML is very complex

4 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. Not just the internet but different applications, platforms, and so on.

5 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. A database that stores XML documents. There are two types. The first is the "XML-enabled database," which is a relational or object-oriented database that has been extended to hold XML data. In this method, there is always a conversion to and from the XML document to the underlying structure such as rows and columns in the relational model. In addition, the XML-enabled database may only store part of the XML document. The second is the "native XML database," which indexes XML documents directly and stores the entire XML document and related elements. Depending on the application, the native XML database may provide better performance than the XML-enabled database. For more information on XML databases

6 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 self-describing. Relational data does not have inherent ordering. A relational database contains tables As we have already learned about the relational data model we know that it is made up of relations (tables), attributes (columns)‏ A relational record is an unordered list of named values An XML document is a tree of nodes

7 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

8 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

9 multiple elements represented in a hierarchy,
including a root“Comments” element and one or more individual “Comment” elements pertaining to a given item.

10 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) * Well-formed. A well-formed document conforms to all of XML's syntax rules. * Valid. A valid document additionally conforms to some semantic rules. These rules are either user-defined, or included as an XML schema or DTD. (wikipedia)‏

11 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. PCDATA Parsed character data: It refers to "usual" characters of the document without any markup tags and can be used to explicitly allow or disallow plain text within an element. Always needs to be in '( )' Example of a DTD on next slide

12 Inline DTD External DTD message.xml message.xml message.dtd
<?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> <?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> message.dtd <?xml version="1.0"?> <!ELEMENT message (to,from,subject,text)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT subject (#PCDATA)> <!ELEMENT text (#PCDATA)>

13 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 Point out the different between DTD and XSD. Validation vs. no data validation. Example of a XSD on next slide

14 The first line is needed. Point out importance of formating for XSD.
<?xml version="1.0"?> <xs:schema xmlns:xs=" targetNamespace=" xmlns=" elementFormDefault="qualified"> <xs:element name="note"> <xs:complexType> <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:complexType> </xs:element> </xs:schema> The first line is needed. Point out importance of formating for XSD.

15 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....

16 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)

17 Examples of XPath <?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore> <book> <title lang="en">Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> </bookstore> Document node Attribute node Element node Example of an XPath expressions: /bookstore Will select the root element bookstore /bookstore/book Selects all book elements that are children of bookstore

18 XQuery Think of XQuery as SQL for a relational database for XML.
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.)‏ Think of XQuery as SQL for a relational database for XML.

19 Example of XQuery Example of an XQuery expressions:
<?xml version="1.0" encoding="ISO "?> <bookstore> <book category="COOKING"> <title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price> </book> </bookstore> Example of an XQuery expressions: doc("books.xml")/bookstore/book/title Will return: <title lang="en">Everyday Italian</title>

20 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>

21 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.

22 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> <PROD_ID>92219</PROD_ID> <PROD_NAME>LABELS</PROD_NAME> <PRICE>12.95</PRICE> <QUANTITY>250</QUANTITY> </ORDER> XML document decomposed into a relation Order Items

23 Another Example..... Sales Order Items table
<SalesOrder Number="123"> <OrderDate> </OrderDate> <CustomerNumber>456</CustomerNumber> <Item Number="1"> <PartNumber>XY-47</PartNumber> <Quantity>14</Quantity> <Price>16.80</Price> </Item> <Item Number="2"> <PartNumber>B-987</PartNumber> <Quantity>6</Quantity> <Price>2.34</Price> </SalesOrder> Items table

24 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 DB2. Architecture of DB2

25 References (1) “Comparison of XML Model and the Relational Model.” DB2 Version 9 for Linux, UNIX, and Windows.10 April < (2) W3Schools. < (3) W3Schools. < (4) Coss Rafael. “DBS 9 pureXML”. IMSS_DB2pureXML_v3.ppt. (5) Coss, Rafael. “XML L2 Skills Transfer - template”. Jan 14, XML_L2~1.ppt (6) Bourret, Ronald. XML “DatabaseProducts“. Ronald Bourret Consulting, writing, and research in XML and database. March 13, < When thinking about designing a database thought about how you will need to store the data should come up. Should you use a database that stores data in a relational model, like we have been learning? Or should we try something different like XML? Or how about both?

26 (7) W3Schools. <http://www.w3schools.com/dtd/default.asp>
(8)Steegmans, Bart. Bourret, Ronald. Olivier, Guvennet.” XML for DB2 Information Integration”. IBM Redbooks .<


Download ppt "XML and The Relational Data Model"

Similar presentations


Ads by Google