Upload
hawlery1989
View
209
Download
1
Tags:
Embed Size (px)
Citation preview
Outlines
Introduction
Why XML for databases?
What's XML database?
XML Structure
Types of XML databases
XML vs. Relational databases
Document Type Definition
XML Schema Definition
Xpath
Xquery
Demo
2
Introduction
Data interchange is critical in today’s networked world
Each application area has its own set of standards for
representing information
XML has become the basis for all new generation data
interchange formats
Earlier generation formats were based on plain text with line
headers indicating the meaning of fields
3
Why XML for databases?
It is more suitable for specifying structured data that is
extracted from databases than HTML
XML was developed was to allow the exchange of semi-structured documents.
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.
4
What’s XML?
XML stands for Extensible Markup Language.
It is designed to describe data and focus on what data is.
It is used to structure store and to send information.
It is easy to understand and is self describing.
XML is derived from Standard Generalized Markup Language
(SGML)
5
<?xml version = "1.0"?>
Structure of XML Data
<library xmlns:mevlana=“http://mevlana.edu.tr”>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
</book>
</library>
<!-- comments -->
6
Start tag
End tag
Element
Attribute
Namespace
Comments
tag
XML
Document
Node
Types of XML databases
There are two major types of XML databases:
XML-enabled: These map all XML to a traditional database,
accepting XML as input and rendering XML as output.
Native XML (NXD): The internal model depends on XML and
uses XML documents as the fundamental unit of storage.
7
XML vs. Relational Database
XML Database
XML data is hierarchical
XML data is self-describing
XML data has inherent
ordering
An XML database contains
collections
8
Relational Database
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 vs. Relational Database
9
<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><ITEM>
<PROD_ID>94866</PROD_ID><PROD_NAME>BINDER</PROD_NAM
E><PRICE>7.95</PRICE><QUANTITY>26</QUANTITY>
</ITEM><ITEM>
<PROD_ID>92219</PROD_ID><PROD_NAME>LABELS</PROD_NAM
E><PRICE>12.95</PRICE><QUANTITY>250</QUANTITY>
</ITEM></ORDER>
Items
Order
XML Document Schema
Database schemas constrain what information can be stored,
and the data types of stored values
XML documents are not required to have an associated schema
Schemas are very important for XML data exchange
Two mechanisms for specifying XML schema
Document Type Definition (DTD)
XML Schema Definition (XSD)
11
Document Type Definition
DTD constraints structure of XML data
What elements can occur
What attributes can/must an element have
What subelements can/must occur inside each element, and how many
times.
DTD does not constrain data types
12
XML Schema Definition
Different data types
XML Schema is itself specified in XML syntax, unlike DTDs
XML Schema is integrated with namespaces
XML Schema is significantly more complicated than DTDs
14
XML Schema is a more sophisticated schema language which addresses
the drawbacks of DTDs. Supports
Querying XML Data
There are several languages used to access XML data from XML
Documents, some are:
XPath
Xquery (most popular)
XML-QL
XQL
etc....
16
XPath
XPath is used to address (select) parts of documents using path
expressions
17
<?xml version="1.0">
<bookstore>
<book><title lang="en">Harry Potter</title><author>J K. Rowling</author> <year>2005</year><price>29.99</price>
</book></bookstore>
Document node
Element node
Attribute node
/bookstore Will select the root element bookstore
/bookstore/book Selects all book elements that are children of bookstore
/bookstore/book/text() Selects all book elements of bookstore without tags
XQuery
XQuery is a general purpose query language for XML data
XQuery is built on XPath expressions
XQuery is derived from the quilt query language, which itself borrows from SQL
XQuery is supported by all database engines (IBM, Oracle, Microsoft, etc.)
XQuery uses FLOWR (for, let, where, order by , result)
for SQL from
where SQL where
order by SQL order by
result SQL select
let allows temporary variables
18
XQuery
19
<?xml version="1.0">
<bookstore>
<book category="COOKING"><title lang="en">Everyday Italian</title><author>Giada De Laurentiis</author><year>2005</year><price>30.00</price>
</book>
</bookstore>
for $x in doc("books.xml")/bookstore/bookwhere $x/price>29return $x/title
Select title
From bookstore/book
Where price>29