XML and The Relational Data Model - PowerPoint PPT Presentation

1 / 26
About This Presentation
Title:

XML and The Relational Data Model

Description:

It is a metalanguage used to represent and manipulate data elements. Similar to HTML in structure, but XML is concerned with the description and ... – PowerPoint PPT presentation

Number of Views:97
Avg rating:3.0/5.0
Slides: 27
Provided by: scie423
Category:

less

Transcript and Presenter's Notes

Title: XML and The Relational Data Model


1
XML and The Relational Data Model
ltauthorgt By Soid Quintero lt/authorgt
2
Overview
  • Define XML
  • XML model vs. relational model
  • XML Documents
  • Xpath
  • XQuery
  • Going from XML to the relational model

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

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.

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.
6
XML Model VS. Relational Model?
  • 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
  • XML data is hierarchical
  • XML data is self-describing
  • XML data has inherent ordering
  • An XML database contains collections

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 rootComments 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.
    ltStudentgt lt/Studentgt )?
  • 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 lt-- XXX --gt symbols for comments
  • XML is case sensitive so, ltStudentgt is not the
    same as ltSTUDENTgt
  • Two types of XML documents commonly used,
    Document Type Definition (DTD) or an XML Schema
    Definitions (XSD)

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.

Example of a DTD on next slide.......
12
Inline DTD
External DTD
message.xml
message.xml
lt?xml version"1.0"?gt lt!DOCTYPE message SYSTEM
"message.dtd"gt ltmessagegt lttogtDavelt/togt
ltfromgtSusanlt/fromgt ltsubjectgtReminderlt/subjectgt
lttextgtDon't forget to buy milk on the way
home.lt/textgt lt/messagegt
lt?xml version"1.0"?gt lt!DOCTYPE message
lt!ELEMENT message (to,from,subject,text)gt
lt!ELEMENT to (PCDATA)gt lt!ELEMENT from
(PCDATA)gt lt!ELEMENT subject (PCDATA)gt
lt!ELEMENT text (PCDATA)gt gt ltmessagegt
lttogtDavelt/togt ltfromgtSusanlt/fromgt
ltsubjectgtReminderlt/subjectgt lttextgtDon't forget
to buy milk on the way home.lt/textgt lt/messagegt
message.dtd
lt?xml version"1.0"?gt lt!ELEMENT message
(to,from,subject,text)gt lt!ELEMENT to
(PCDATA)gt lt!ELEMENT from (PCDATA)gt lt!ELEMENT
subject (PCDATA)gt lt!ELEMENT text (PCDATA)gt
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

Example of a XSD on next slide.......
14
lt?xml version"1.0"?gt ltxsschema
xmlnsxs"http//www.w3.org/2001/XMLSchema" target
Namespace"http//www.w3schools.com" xmlns"http/
/www.w3schools.com" elementFormDefault"qualified"
gt ltxselement name"note"gt ltxscomplexTypegt
ltxssequencegt ltxselement name"to"
type"xsstring"/gt ltxselement name"from"
type"xsstring"/gt ltxselement name"heading"
type"xsstring"/gt ltxselement name"body"
type"xsstring"/gt lt/xssequencegt
lt/xscomplexTypegt lt/xselementgt lt/xsschemagt
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
lt?xml version"1.0" encoding"ISO-8859-1"?gt ltbook
storegt ltbookgt lttitle lang"en"gtHarry
Potterlt/titlegt ltauthorgtJ K. Rowlinglt/authorgt
ltyeargt2005lt/yeargt ltpricegt29.99lt/pricegt lt/bookgt
lt/bookstoregt
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
  • 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.)?

19
Example of XQuery
lt?xml version"1.0" encoding"ISO-8859-1"?gt ltbook
storegt ltbook category"COOKING"gt lttitle
lang"en"gtEveryday Italianlt/titlegt
ltauthorgtGiada De Laurentiislt/authorgt
ltyeargt2005lt/yeargt ltpricegt30.00lt/pricegt lt/bookgt
lt/bookstoregt
Example of an XQuery expressions doc("books.xml"
)/bookstore/book/title Will return lttitle
lang"en"gtEveryday Italianlt/titlegt
20
The XQuery FLWOR
  • for Iterates through a sequence, bind variable
    to items
  • let binds a variable to a sequence
  • whereeliminates 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/pricegt29 return x/title Will return lttitle
lang"en"gtEveryday Italianlt/titlegt
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
ltORDERgt ltORDER_ID83492 CUST_ID93457gt
ltITEMgt ltPROD_IDgt94872lt/PROD_IDgt ltPROD_NAMEgtPENlt/
PROD_NAMEgt ltPRICEgt19.95lt/PRICEgt ltQUANTITYgt30lt/QU
ANTITYgt lt/ITEMgt ltITEMgt ltPROD_IDgt94866lt/PROD_I
Dgt ltPROD_NAMEgtBINDERlt/PROD_NAMEgt ltPRICEgt7.95lt/PR
ICEgt ltQUANTITYgt26lt/QUANTITYgt lt/ITEMgt
ltITEMgt ltPROD_IDgt92219lt/PROD_IDgt ltPROD_NAMEgtLABEL
Slt/PROD_NAMEgt ltPRICEgt12.95lt/PRICEgt ltQUANTITYgt250
lt/QUANTITYgt lt/ITEMgt lt/ORDERgt
XML document decomposed into a relation
Order
Items
23
Another Example.....
Sales Order
ltSalesOrder Number"123"gt ltOrderDategt2003-07-2
8lt/OrderDategt ltCustomerNumbergt456lt/CustomerNumbergt
ltItem Number"1"gt ltPartNumbergtXY-47lt/PartNum
bergt ltQuantitygt14lt/Quantitygt ltPricegt16.80lt/Pri
cegt lt/Itemgt ltItem Number"2"gt ltPartNumbergtB-9
87lt/PartNumbergt ltQuantitygt6lt/Quantitygt ltPricegt
2.34lt/Pricegt lt/Itemgt lt/SalesOrdergt
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. 2007 lthttp//publib.boulder.ibm
.com/infocenter/db2luw/v9/topic/com.ibm.db2.udb.ap
dv.embed.doc/doc/c0023811.htmgt. (2) W3Schools.
lthttp//www.w3schools.com/xpath/default.aspgt (3)
W3Schools. lthttp//www.w3schools.com/xquery/defaul
t.aspgt (4) Coss Rafael. DBS 9 pureXML.
IMSS_DB2pureXML_v3.ppt. (5) Coss, Rafael. XML
L2 Skills Transfer - template. Jan 14, 2005.
XML_L21.ppt (6) Bourret, Ronald. XML
DatabaseProducts. Ronald Bourret Consulting,
writing, and research in XML and database. March
13, 2007. lthttp//www.rpbourret.com/xml/XMLDatabas
eProds.htmxmlanddatabasesgt
26
(7) W3Schools. lthttp//www.w3schools.com/dtd/defau
lt.aspgt (8)Steegmans, Bart. Bourret, Ronald.
Olivier, Guvennet. XML for DB2 Information
Integration. IBM Redbooks .lthttp//www.redbooks.i
bm.com/redbooks/SG246994/wwhelp/wwhimpl/java/html/
wwhelp.htmgt
Write a Comment
User Comments (0)
About PowerShow.com