90
XML - QL XML - QL A Query Language for XML A Query Language for XML Version 0.6

XML - QL A Query Language for XML

  • Upload
    mina

  • View
    89

  • Download
    1

Embed Size (px)

DESCRIPTION

XML - QL A Query Language for XML. Version 0.6. Outline. Introduction Examples in XML-QL A Data Model for XML Advanced Examples in XML-QL Extensions and Open Issues Summary. Why do we need a query language ?. XML standard doesn't address: - PowerPoint PPT Presentation

Citation preview

Page 1: XML - QL A Query Language for XML

XML - QLXML - QLA Query Language for A Query Language for

XMLXMLVersion 0.6

Page 2: XML - QL A Query Language for XML

04/2000 XML-QL 2

Outline

Introduction

Examples in XML-QL

A Data Model for XML

Advanced Examples in XML-QL

Extensions and Open Issues

Summary

Page 3: XML - QL A Query Language for XML

04/2000 XML-QL 3

Why do we need a query language ?

XML standard doesn't address: Extraction : How will data be extracted from large XML

documents?

Transformation : How will XML data be exchanged between user communities using different but related

DTD's?

Integration : How will XML data from multiple XML sources be integrated?

Conversion of data between relational or OO to XML

Page 4: XML - QL A Query Language for XML

04/2000 XML-QL 4

What Does XML-QL do ?

Extraction - of data pieces from XML documents

Transformation - Map XML data between different DTDs

Integration/Combination of XML data from different sources

Page 5: XML - QL A Query Language for XML

04/2000 XML-QL 5

How will data be extracted from large XML documents?

Page 6: XML - QL A Query Language for XML

04/2000 XML-QL 6

Data Transformation

How will XML data be exchanged between user communities using different but related DTD's?

Page 7: XML - QL A Query Language for XML

04/2000 XML-QL 7

Data Integration

Page 8: XML - QL A Query Language for XML

04/2000 XML-QL 8

XML - QL “Relational complete”

Can expression selection, join etc. Nested queries

Precise semantic To support reasoning

XML - specific features Regular-path expressions & tag variables No DTD required, exploit when available

Rewritability Preserve order and Association

Ordering of elements, grouping of subelements Server-side processing

Prototype implementation in Java.

Page 9: XML - QL A Query Language for XML

04/2000 XML-QL 9

Requirements for a query language for XML

Selection and extraction Preserve structure. Reduction Restructuring Join

(will be shown in the first part)

Page 10: XML - QL A Query Language for XML

04/2000 XML-QL 10

Requirements for a query language for XML

Tag Variables Regular path expressions Transforming XML data between DTDs No schema required Indexing Sorting.

(will be shown in the advanced part)

Page 11: XML - QL A Query Language for XML

04/2000 XML-QL 11

Outline Introduction

Examples in XML-QL

A Data Model for XML

Advanced Examples in XML-QL

Extensions and Open Issues

Summary

Page 12: XML - QL A Query Language for XML

04/2000 XML-QL 12

Class Number – cs 401Class Number – cs 401

Class- web and xmlClass- web and xml

Instructor – Sanjay MadriaInstructor – Sanjay Madria

Lesson Title - XML-QLLesson Title - XML-QL

Page 13: XML - QL A Query Language for XML

04/2000 XML-QL 13

BIB . DTD

<!ELEMENT book (author+, title, publisher)>

<!ATTLIST book year CDATA>

<!ELEMENT article (author+, title, year?, (shortversion|longversion))>

<!ATTLIST article type CDATA>

<!ELEMENT publisher (name, address)>

<!ELEMENT author (firstname?, lastname)>

Page 14: XML - QL A Query Language for XML

04/2000 XML-QL 14

Basic Examples: Selection/Extraction

Find all the names of the authors whose publisher is

Addison-Wesley:

WHERE <book>

<publisher><name> Addison-Wesley </name></publisher>

<title> $t </title>

<author> $a </author>

</book> IN "www.a.b.c/bib.xml"

CONSTRUCT $a

Page 15: XML - QL A Query Language for XML

04/2000 XML-QL 15

Basic Examples, syntax (cont)

The use of </> instead of </XXX>:

WHERE <book>

<publisher><name> Addison-Wesley </></>

<title> $t </>

<author> $a </>

</> IN "www.a.b.c/bib.xml"

CONSTRUCT $a

Page 16: XML - QL A Query Language for XML

04/2000 XML-QL 16

Result of first query:

The output is in XML form:

<lastname> Date </lastname>

<lastname> Darwen </lastname>

<lastname> Date </lastname>

Page 17: XML - QL A Query Language for XML

04/2000 XML-QL 17

Constructing new XML data:Reduction & Restructre

WHERE <book>

<publisher> <name> Addison-Wesley </></>

<title> $t </>

<author> $a </>

</> IN "www.a.b.c/bib.xml"

CONSTRUCT <result>

<author> $a </>

<title> $t </>

</>

Page 18: XML - QL A Query Language for XML

04/2000 XML-QL 18

XML-QL Example Data<bib> <book year=“1995> <title> An Introduction to DB Systems </title>

<author> <lastname> Date </lastname></author>

<publisher><name> Addison-Wesley</name> </publisher>

</book><book year=“1995>

<title> Foundations for OR Databases </title><author> <lastname> Date

</lastname></author> <author> <lastname> Darwen

</lastname></author> <publisher><name> Addison-Wesley</name>

</publisher></book>

</bib>

Page 19: XML - QL A Query Language for XML

04/2000 XML-QL 19

Constructing new XML data: (result)

<result>

<author> <lastname> Date </lastname> </author>

<title> An Introduction to DB Systems </title>

</result>

<result>

<author> <lastname> Date </lastname> </author>

<title> Foundation for OR Databases</title>

</result>

<result>

<author> <lastname> Darwen </lastname> </author>

<title> Foundation for Object/Relational Databases: The Third Manifesto </title>

</result>

Page 20: XML - QL A Query Language for XML

04/2000 XML-QL 20

Grouping with Nested Queries: Preserve structure

WHERE <book> $p <book> IN "www.a.b.c/bib.xml” ,

<publisher> <name>Addison-Wesley </> </> IN $p ,

<title> $t </> IN $p

CONSTRUCT <result>

<title> $t </>

WHERE <author> $a </> IN $p

CONSTRUCT <author> $a </>

</>

Page 21: XML - QL A Query Language for XML

04/2000 XML-QL 21

Reduction

Where <book> <publisher> <name>

Addition-wesley</> </>

<title>$t </> Element_As $x

<author> $a</> Element_As $y

</> </> IN www.a.b.c/bib/xml

Construct <result> $x $y </>

Page 22: XML - QL A Query Language for XML

04/2000 XML-QL 22

Grouping with Nested Queries:Preserve structure

WHERE <book>

<publisher> <name>Addison-Wesley</> </>

<title> $t </>

</> CONTENT_AS $p IN "www.a.b.c/bib.xml”

CONSTRUCT <result>

<title> $t </>

WHERE <author> $a </> IN $p

CONSTRUCT <author> $a </>

</>

Page 23: XML - QL A Query Language for XML

04/2000 XML-QL 23

Grouping with Nested Queries:(result)

<result>

<title> An Introduction to Database Systems </title>

<author> <lastname> Date </lastname> </author>

</result>

<result>

<title> Foundation for Object/Relational Databases: The Third Manifesto </title>

<author> <lastname> Date </lastname> </author>

<author> <lastname> Darwen </lastname> </author>

</result>

Page 24: XML - QL A Query Language for XML

04/2000 XML-QL 24

Joining element by values:WHERE <article>

<author>

<firstname> $fn </> -- firstname $f

<lastname> $ln </> -- firstname $l

</>

</> CONTENT_AS $a IN "www.a.b.c/bib.xml”,

<book year = $y >

<author>

<firstname> $fn </> -- join the same firstname $f

<lastname> $ln </> -- join the same lastname $l

</>

</> IN "www.a.b.c/bib.xml”,

$y > 1995

CONSTRUCT <article> $a </>

Page 25: XML - QL A Query Language for XML

04/2000 XML-QL 25

ELEMENT_AS Vs. CONTENT_AS:

WHERE <article>

<author>

<firstname> $fn </> -- firstname $fn

<lastname> $ln </> -- firstname $ln

</>

</> ELEMENT_AS $a IN "www.a.b.c/bib.xml”,

CONSTRUCT $a -- No need for <article> …. </>

Page 26: XML - QL A Query Language for XML

04/2000 XML-QL 26

Outline Introduction

Examples in XML-QL

A Data Model for XML

Advanced Examples in XML-QL

Extensions and Open Issues

Summary

Page 27: XML - QL A Query Language for XML

04/2000 XML-QL 27

A data model for XML

XML : data format syntaxQuery operations assume data modelXML Graph

Directed, Labeled graph Element tags on edges Attribute values on nodes Each node is represented by OID (unique string) Unordered & ordered models Leaves labeled with values

Page 28: XML - QL A Query Language for XML

04/2000 XML-QL 28

XML graph for example XML book elements

(year=“1995”)

book book

titleauthor

publisher

title author

author

nameAn introduction …

Addison-Wesley

Addison-Wesley

Foundations for ...

name lastname

DateDate Datwen

lastnamelastname

publisher

(year=“1998”)

root

Page 29: XML - QL A Query Language for XML

04/2000 XML-QL 29

Element Identity, IDs, and ID Reference:

XML reserve an attribute of type ID, which allows a unique key to be associated with an element.

An attribute IDREF allows an element to refer to another element with the designated key, and IDREFS may refer to multiple elements.

Example: adding attribute ID and author types ID and IDREFS:

<!ATTLIST person ID ID #REQUIRED>

<!ATTLIST article auther IDREFS #IMPLIED>

Page 30: XML - QL A Query Language for XML

04/2000 XML-QL 30

Element Identity, IDs, and ID Reference: (cont)

and definitions:<person ID = “o123”>

<firstname> John </firstname><lastname> Smith </lastname>

</person><person ID = “o234”>

...</person><article author = “o123 o234”>

<title> … </title><year> 1995 </year>

</article>

Page 31: XML - QL A Query Language for XML

04/2000 XML-QL 31

XML graph including ID & IDREFS

first name titlefirst namelast name yearlast name

author

personperson

article

John Smith 1995

root

Page 32: XML - QL A Query Language for XML

04/2000 XML-QL 32

Writing queries using IDs Without IDs:

WHERE <article><author><lastname> $n </></></> IN “abc.xml”

Using IDREF: (All last name, title pairs) WHERE <article author = $i>

<title> </> ELEMENT_AS $t

</>,

<person ID = $i>

<lastname> </> ELEMENT_AS $l

</>

CONSTRUCT <result> $t $l </>

Page 33: XML - QL A Query Language for XML

04/2000 XML-QL 33

Another Example:

<catalogue>

<book id = “b1”

author idref = “a1”>

<title>Memoris…</title>

<year>1997</year>

</book>

</author id = “a1”>

<publication idref = “b1”>

<first>Arthur</first>

<last>Golden</last>

</author>

</catalogue>

catalogue

book author

GoldenArthur1997Memories...

publication

author

oid1

oid2

b1 a1

publication=b1author=a1

Page 34: XML - QL A Query Language for XML

04/2000 XML-QL 34

Scalar Values:Only leaf nodes in the XML may contain values, and

they may have only one value. example: the XML fragment:

<title> A trip to <titlepart> The Moon </titlepart> </title>

can be translated in order to fit the data model into:

<title>

<CDATA> A trip to </CDATA>

<titlepart> <CDATA> The Moon </CDATA> </titlepart>

</title>The value of a leaf node is its oid.

Page 35: XML - QL A Query Language for XML

04/2000 XML-QL 35

Scalar Values: (cont)

<title>

<CDATA>A trip to </CDATA>

<titlepart> <CDATA> The Moon </CDATA> </titlepart>

</title>

CDATA

CDATA

title

titlepart

“The Moon”

“A trip to”

XML graph ->

Page 36: XML - QL A Query Language for XML

04/2000 XML-QL 36

Element Order

XML-QL supports two distinct data model: an unordered and ordered one.

An ordered graph is like an unordered one but include , for each node, a total order on its successors.

The price for an ordered model is a more complex semantic of the query language and less efficient.

Page 37: XML - QL A Query Language for XML

04/2000 XML-QL 37

Mapping XML-graphs into XML-documents

XML graph don’t have a unique representation, as XML document because: element order is unspecified. sharing of nodes.

To create a XML document we have to choose some order that conform to a DTD.

Page 38: XML - QL A Query Language for XML

04/2000 XML-QL 38

Outline Introduction

Examples in XML-QL

A Data Model for XML

Advanced Examples in XML-QL

Extensions and Open Issues

Summary

Page 39: XML - QL A Query Language for XML

04/2000 XML-QL 39

Advanced examples in XML-QLTag VariablesRegular - path ExpressionsTransforming XML data Integrating from multiple XML sourcesNo schema requiredFunctions definitions and DTD’sExternal functionsOrdered model - Sorting, Indexing

Page 40: XML - QL A Query Language for XML

04/2000 XML-QL 40

Tag Variables, No schema required

WHERE < $p > -- $p can be {article, book}

<title> $t </>

<year>1995 </> -- referring attr. as an element

< $e ><lastname> Date </> </>

</> IN "bib.xml",

$e IN {author, editor}

CONSTRUCT < $p >

<title> $t </>

< $e > Date </>

</>

All publications published in 1995 in which Date is either an author, or an editor

Page 41: XML - QL A Query Language for XML

04/2000 XML-QL 41

Query Result

<book>

<author>Date</author>

<title>An Introduction to Database Systems </title>

</book>

<article>

<author>Date</author>

<title>The New Jersey Machine-Code Toolkit</title>

</article>

Page 42: XML - QL A Query Language for XML

04/2000 XML-QL 42

Regular Path Expressions

XML data can specify nested and cyclic structures, such as trees, directed acyclic graphs, and arbitrary graphs.

The following DTD defines a self-recursive element part:<!ELEMENT part (name brand part*)>

<!ELEMENT name CDATA>

<!ELEMENT brand CDATA>

Page 43: XML - QL A Query Language for XML

04/2000 XML-QL 43

Regular Path Expressions (cont)

Here part* is a regular path expression, and

matches any sequence of edges, all of which

are labeled part:

WHERE < part* >

<name> $r </>

<brand> Ford </>

</> IN "www.a.b.c/parts.xml"

CONSTRUCT <result> $r </>

Page 44: XML - QL A Query Language for XML

04/2000 XML-QL 44

Regular Path Expressions (cont)

the path definition :<part*><name> $r </><brand> Ford </> </>

is equivalent to the following infinite sequence of patterns:

<name> $r </> <brand> Ford </> <part> <name> $r </> <brand> Ford </> </> <part> <part> <name> $r </> <brand> Ford </> </> </> <part> <part> <part> <name> $r </> <brand> Ford </>

</> </> </> ...

Page 45: XML - QL A Query Language for XML

04/2000 XML-QL 45

Regular Path Expressions (cont)

The wildcard ‘ * ‘ matches any tag and appear wherever a tag is permitted:

Example:

WHERE < $* >

<name> $r </>

<brand> Ford </>

</> IN "www.a.b.c/parts.xml"

CONSTRUCT <result> $r </>

Page 46: XML - QL A Query Language for XML

04/2000 XML-QL 46

Regular Path Expressions (cont)

‘ . ‘ denotes concatation of regular expression

<part.part.name>……</> = <part><part><name>… … </></></>

‘ | ‘ denotes alternation of regular expression

‘ + ‘ operator means one or more:

<part+> = <part.part*>

Tag variables make it possible to write a query that can be applied to two or more XML data sources with similar but not identical DTDs.

Page 47: XML - QL A Query Language for XML

04/2000 XML-QL 47

Regular Path Expressions (cont)

WHERE <*.Part+.(subpart|component)> $r </>

IN ”parts.xml” -- please take a look at parts.XML

CONSTRUCT <result>$r</>

Result:<result><name>Motor</name><brand>Hamilton</brand></result>

<result>

<brand>B&O</brand>

<part><name>A2D</name> <brand>AMD</brand></part>

<name>Woofer</name>

</result>

<result><name>Speakers</name><brand>Labtec</brand></result>

Page 48: XML - QL A Query Language for XML

04/2000 XML-QL 48

Transforming XML dataTranslate data from one DTD into another.Example: besides the BIB. DTD we have other

DTD that defines a person:

<!ELEMENT person (lastname, firstname,

address?, phone?, publicationtitle*)Next query transform data that conforms to

BIB.DTD into data that conforms to Person DTD.The Query uses OID’s(Object identifiers) and

Skolem functions to group results in the same <person> element.

Page 49: XML - QL A Query Language for XML

04/2000 XML-QL 49

Transforming XML data with Skolem function

WHERE <$*> <author> <firstname> $fn </> <lastname> $ln </>

</><title> $t </>

</> IN "www.a.b.c/bib.xml",CONSTRUCT <person ID=PersonID($fn, $ln)> <firstname> $fn </> <lastname> $ln </> <publicationtitle> $t </> </>

Page 50: XML - QL A Query Language for XML

04/2000 XML-QL 50

Query Result

<person> <firstname>Mary</firstname><lastname>Fernandez</lastname><publicationtitle>The New Jersey Machine-Code

Toolkit</publicationtitle></person><person>

<firstname>Dan</firstname><lastname>Date</lastname><publicationtitle>The New Jersey Machine-Code

Toolkit</publicationtitle></person>

Page 51: XML - QL A Query Language for XML

04/2000 XML-QL 51

Integrating data from multiple XML sources

WHERE <person><name></> ELEMENT_AS $n

<ssn> $ssn </> </> IN ”payroll.xml", -- take a look at payroll.XML <taxpayer> <ssn> $ssn </> <income></> ELEMENT_AS $i </> IN "taxpayers.xml” -- take a look…CONSTRUCT <result> $n $i </>

Page 52: XML - QL A Query Language for XML

04/2000 XML-QL 52

Integrating data from multiple XML sources (result)

<result><income>55000</income><name>M.Smith</name>

</result><result>

<income>1430000</income> <name>R. Johnson</name>

</result><result>

<income>35000</income> <name>J. Doe</name>

</result>

Page 53: XML - QL A Query Language for XML

04/2000 XML-QL 53

Integrating data from multiple XML sources (Skolem function)

{ WHERE <person> <name> </> ELEMENT_AS $n<ssn> $ssn </>

</> IN ”payroll.xml" CONSTRUCT <result ID=SSNID($ssn)> $n </>}{ WHERE <taxpayer>

<ssn> $ssn </><income> </> ELEMENT_AS $i

</> IN "taxpayers.xml" CONSTRUCT <result ID=SSNID($ssn)> $n $i </>}

Page 54: XML - QL A Query Language for XML

04/2000 XML-QL 54

Integrating data (result)

<result>

<name>M. Smith</name>

<income>55000</income>

</result>

<result><income>120000</income></result>

<result>

<name>R. Johnson</name>

<income>1430000</income>

</result>

<result><name>P. Kent</name></result>

<result>

<name>J. Doe</name> <income>35000</income>

</result>

Page 55: XML - QL A Query Language for XML

04/2000 XML-QL 55

Integrating data (cont) All titles published in ‘95, in addition the month of journal articles and the publishers for books:WHERE < $e >

<title> $t </><year> 1995 </>

</> CONTENT_AS $p IN "www.a.b.c/bib.xml"CONSTRUCT <result ID=ResultID($p)> <title> $t </> </>

{ WHERE $e = ”article",<month> $m </> IN $p

CONSTRUCT <result ID=ResultID($p)> <month> $m </> </> }{ WHERE $e = "book",

<publisher> $q </> IN $p CONSTRUCT <result ID=ResultID($p)> <publisher> $q </> </> }

Page 56: XML - QL A Query Language for XML

04/2000 XML-QL 56

Query Result

<result>

<title>The New Jersey Machine-Code Toolkit</title>

<month>June</month>

</result>

<result>

<title>An Introduction to Database Systems </title>

<publisher>Addison Wesley</publisher>

</result>

Page 57: XML - QL A Query Language for XML

04/2000 XML-QL 57

Functions definitions and DTD’s

function query() {

CONSTRUCT <result>findDeclaredIncomes("taxpayers.xml","payroll.xml")

</result>}function findDeclaredIncome($Taxpayers,$Employees) {

WHERE <taxpayer><ssn> $s </> <income> $x </></> IN $Taxpayer,

<employee><ssn> $s </> <name> $n </> </> IN $Employees

CONSTRUCT <result><name> $n </><income> $x </> </>}

Page 58: XML - QL A Query Language for XML

04/2000 XML-QL 58

Functions definitions and DTD’s (cont)

Restrictions by DTD’s:function findDeclaredIncome (

$Taxpayers:”www.irs.gov/tp.dtd”,

$Employees:”www.employees.org/employeess.dtd”

:“www.my.site.com/myresult.dtd” )

{

WHERE ….

CONSTRUCT ….

}

Page 59: XML - QL A Query Language for XML

04/2000 XML-QL 59

Embedding queries in data<result>

<articles>WHERE <article> <title> $t </><year> $y </>

</> IN “www.a.b.c/bib.xml”, $y > 1995CONSTRUCT <title> $t </>

</><books>

WHERE <book> <title> $t </> <year> $y </> </> IN “www.a.b.c/bib.xml”, $y >1995

CONSTRUCT <title> $t </> </>

</>

Page 60: XML - QL A Query Language for XML

04/2000 XML-QL 60

Support for an ordered model:

Variable order is important for binding Example:

WHERE <a><b> $x </b> <c> $y </c> </a> -- and WHERE <a><c> $y </c> <b> $x </b> </a>

will match the same objects but by different order. Lets take the following XML data:

<a><b> string1 </b><c> string2 </c><b> string3 </b><c> string4 </c>

</a>

Page 61: XML - QL A Query Language for XML

04/2000 XML-QL 61

Support for ordered model (cont)

Under the definition of where in

WHERE <a><b> $x </b> <c> $y </c> </a>

The output will be in the order : $x $y

string1 string2

string1 string4

string3 string2

string3 string4

Page 62: XML - QL A Query Language for XML

04/2000 XML-QL 62

Support for ordered model (cont)

Under the definition of where in

WHERE <a><c> $y </c> <b> $x </b> </a>

The output will be in the order : now the output will be in the ordered first by $y and than by $x)

$x $y

string1 string2

string3 string2

string1 string4

string3 string4

Page 63: XML - QL A Query Language for XML

04/2000 XML-QL 63

Indexes for element:

XML support element-order variables.Example:

<a[$i]> … </>

<$x[$j]> … </>here $i and $j are bind to an integer 0,

1, 2 … that represent the index in the local order of the edges.

Page 64: XML - QL A Query Language for XML

04/2000 XML-QL 64

Indexes for element (graph)

(year=“1995”)

book [0] book[1]

title[0]author[2]

publisher[1]

title[0] author[3]

author[2]

name[0]An introduction …

Addison-Wesley

Addison-Wesley

Foundations for ...

name[0] lastname[0]

DateDate Datwen

lastname[0]

lastname[0]

publisher[1]

(year=“1998”)

( 1 )

( 13 )

( 12 )

( 11 )

( 10 )( 9 )

( 8 )

( 7 )( 5 )

( 6 )( 4)( 3 )

( 2 )

( 15 )

( 14 )

root

Page 65: XML - QL A Query Language for XML

04/2000 XML-QL 65

Indexes for element: (cont.)

Example:

retrieves all the persons whose lastname precedes the firstname:

WHERE <person> $p </> IN “www.a.b.c/people.xml”

<firstname [$k] > $x </> IN $p,

<lastname[$j] > $y </> IN $p,

$j < $k

CONSTRUCT <person> $p </>

Page 66: XML - QL A Query Language for XML

04/2000 XML-QL 66

ORDER-BY:Order publications by year and month:preserve the order in the original document for publications within the same year/month

WHERE <pub> $p </> IN “www.a.b.c/people.xml”,<title> $t </> IN $p,<year> $y </> IN $p,<month> $m </> IN $p

ORDER-BY value($y),value($m)

CONSTRUCT <result> $t </> value function returns the CDATA value of a node In the absence of value the result would be ordered by OIDs

Page 67: XML - QL A Query Language for XML

04/2000 XML-QL 67

ORDER-BY: (cont.)

Reverse the order of all authors in a publication:

WHERE <pub> $p </> IN “www.a.b.c/people.xml”,CONSTRUCT <pub>

WHERE <author[$k]> $a </> IN $pORDER-BY $k DESCENDINGCONSTRUCT <author> $a </>WHERE < $e > $v </> IN $p

$e != “author”CONSTRUCT <$e> $v </>

</pub>

Page 68: XML - QL A Query Language for XML

04/2000 XML-QL 68

Outline Introduction

Examples in XML-QL

A Data Model for XML

Advanced Examples in XML-QL

Extensions and Open Issues

Summary

Page 69: XML - QL A Query Language for XML

04/2000 XML-QL 69

Extensions and open issues:

EntitiesUser-defined predicatesString regular expressionsName spacesAggregatesXML syntaxExtensions to other XML-related standard

Page 70: XML - QL A Query Language for XML

04/2000 XML-QL 70

EntitiesRecognizing entity references:

e.g : <!ENTITY % M “Mary” >

Page 71: XML - QL A Query Language for XML

04/2000 XML-QL 71

WHERE <person>

<firstname> &M </>

<address> $a </>

</> ELEMENT_AS $x IN “abc.xml”,

ATTAddress($a)

CONSTRUCT $x

User-defined predicates

Page 72: XML - QL A Query Language for XML

04/2000 XML-QL 72

WHERE <person>

<firstname> &M </>

<lastname> ‘Fern*’ </>

<address> $a </>

</> ELEMENT_AS $x IN “abc.xml”,

ATTAddress($a)

CONSTRUCT $x

String regular expressions

Page 73: XML - QL A Query Language for XML

04/2000 XML-QL 73

Name spaces

WHERE <person>

<lastname> ‘Fern*’ </>

<US:address> $a </>

</> ELEMENT_AS $x IN “abc.xml”,

ATTAddress($a)

CONSTRUCT $x

Page 74: XML - QL A Query Language for XML

04/2000 XML-QL 74

Aggregated

WHERE <book>

<publisher> </> ELEMENT_AS $p,

<price> $x </>,

</> IN “bib.xml”

GROUP-BY $p

CONSTRUCT <result ID=f($p)> $p

<lowest-price> $min($x) </>

<highest-price> $max($x) </>

</>

Page 75: XML - QL A Query Language for XML

04/2000 XML-QL 75

Outline Introduction

Examples in XML-QL

A Data Model for XML

Advanced Examples in XML-QL

Extensions and Open Issues

Summary

Page 76: XML - QL A Query Language for XML

04/2000 XML-QL 76

Other Query Languages

XSL vs. XML-QL XSL - Intended primarily for specifying style and

layout of XML documents, consists: Transformation operations Formatting vocabulary

XML-QL XSLXML output x xno schema required x xdata extraction x xdata restructuring x xdata integration xschema browsing x xrelational complete x

Page 77: XML - QL A Query Language for XML

04/2000 XML-QL 77

Other Query Languages(cont)

Other competents query languages are: Lorel, YATL, XQL, XML-GL, WEBL

Comparison of simple query:XML-QL

CONSTRUCT <bib> {

WHERE <bib> <book year=$y>

<title>$t</> <publisher><name>Addison-Wesley</></>

</>

</bib> IN “www.bn.com/bib.xml”,

$y>1991

CONSTRUCT <book year=$y><title>$t</></>

} </bib>

Page 78: XML - QL A Query Language for XML

04/2000 XML-QL 78

Other Query Languages(cont)

YATL

make

bib [ *book [ @year [ $y ],

title [ $t ] ] ]

match “www.bn.com/bib.xml” with

bib [ *book [ @year [ $y ],

title [ $t ] ],

publisher [ name [ $n ] ] ]

where

$n = “Addison-Wesley” and $y > 1991

Page 79: XML - QL A Query Language for XML

04/2000 XML-QL 79

Other Query Languages(cont)

XQL:

document(“http://www.bn.com”)/bib {

book[publisher/name=“Addison-Wesley” and @year>1991] { @year | title }

} -- XQL doesn’t have constructor clause

Page 80: XML - QL A Query Language for XML

04/2000 XML-QL 80

Other Query Languages(cont)

LOREL:

select xml(bib:(

(select xml(book:{@year:y, title:t})

from bib.book b, b.title t, b.year y

where b.publisher = “Addison-Wesley” and y>1991)})

Page 81: XML - QL A Query Language for XML

04/2000 XML-QL 81

Other Query Languages(cont)

XML-QL LOREL XSL XQL XML-GL

XML output x x x x

All Query operations x x x

No schema required x x x x x

XML representation x

XML embedded x x x x

Exploit avail. schema x x

Preserve order x x x x x

Page 82: XML - QL A Query Language for XML

04/2000 XML-QL 82

Summary/Conclusions XML-QL is a declarative language which provides

support for querying, constructing, transforming, and integrating XML data

XML-QL supports both ordered and unordered view on XML document

XML-QL is based on similar database research suggested model of Semi-structured data

XML-QL satisfy the absolute set of requirements from query language cited in XML Query Requirements of W3C Working Draft

XML-QL is good candidate to be the new XML standard query language

Page 83: XML - QL A Query Language for XML

04/2000 XML-QL 83

BibliographyArticles: XML-QL:A Query Language for XML, W3C 19/8/98, 99

Quering XML Data - IEEE1999

XML Query Requirements - W3c Working draft 31/1/00

XML Query Languages:Experiences and Exemplars-~mff

WWW sites: www.research.att.com/~mff/xmlql

db.cis.upenn.edu/~adeutsch/xmlql-demo/html/

www-db.research.belllabs.com/user/simeon/ xquery.html

Page 84: XML - QL A Query Language for XML

04/2000 XML-QL 84

Appendix - XML data Examples:

BIB . DTD:

<!ELEMENT book (author+, title, publisher)>

<!ATTLIST book year CDATA>

<!ELEMENT article (author+, title, year?, (shortversion|longversion))>

<!ATTLIST article type CDATA>

<!ELEMENT publisher (name, address)>

<!ELEMENT author (firstname?, lastname)>

Page 85: XML - QL A Query Language for XML

04/2000 XML-QL 85

Appendix - XML data Examples:

BIB . XML:<bib> <book year="1995">

<!-- A good introductory text --><title> An Introduction to Database Systems </title><author> <lastname> Date </lastname> </author><publisher><name> Addison-Wesley </name ></publisher>

</book> <book year="1998">

<title> Foundation for Object/Relational Databases: The ThirdManifesto </title>

<author> <lastname> Date </lastname> </author><author> <lastname> Darwen </lastname> </author><publisher> <name> Addison-Wesley </name > </publisher>

</book></bib>

Page 86: XML - QL A Query Language for XML

04/2000 XML-QL 86

Appendix - XML data Examples

Parts.DTD:

<?xml version="1.0"?><!DOCTYPE Parts [<!ELEMENT Parts (part+)><!ELEMENT part (name,brand,(part|subpart|component)*)><!ELEMENT subpart (name, brand) ><!ELEMENT component (name, brand, part*) ><!ELEMENT name (#PCDATA)><!ELEMENT brand (#PCDATA)>]>

Page 87: XML - QL A Query Language for XML

04/2000 XML-QL 87

Appendix - XML data Examples

Parts.XML:

<Parts><part>

<name>Green Power Juicer</name><brand>Green Power</brand><subpart>

<name>Motor</name><brand>Hamilton</brand>

</subpart></part>

Page 88: XML - QL A Query Language for XML

04/2000 XML-QL 88

Appendix - XML data ExamplesParts.XML continue...

<part> <name>Toyota Tercel</name> <brand>Toyota</brand> <part> <name>Sony Stereo X11-3</name> <brand>Sony</brand> <component> <name>Woofer</name>

<brand>B&amp;O</brand> <part><name>A2D</name>

<brand>AMD</brand></part></component><subpart>

<name>Speakers</name><brand>Labtec</brand>

</subpart></part>

</part></Parts>

Page 89: XML - QL A Query Language for XML

04/2000 XML-QL 89

Appendix - XML data ExamplesPayroll.XML<Payroll>

<person><ssn>100-0000-001</ssn><name>J. Doe</name><salary>35000</salary> </person>

<person><ssn>100-0000-002</ssn><name>M. Smith</name><salary>73000</salary> </person>

<person><ssn>100-0000-003</ssn><name>R. Johnson</name><salary>1400000</salary> </person>

<person><ssn>100-0000-004</ssn><name>P. Kent</name><salary>33000</salary> </person>

</Payroll>

Page 90: XML - QL A Query Language for XML

04/2000 XML-QL 90

Appendix - XML data ExamplesTaxPayers.XML:<IRS>

<taxpayer> <ssn>100-0000-001</ssn><income>35000</income><taxes>7000</taxes> </taxpayer>

<taxpayer> <ssn>100-0000-002</ssn><income>55000</income><taxes>3000</taxes> </taxpayer>

<taxpayer><ssn>100-0000-003</ssn><income>1430000</income><taxes>25000</taxes> </taxpayer>

<taxpayer> <ssn>100-0000-005</ssn><income>120000</income><taxes>30000</taxes> </taxpayer>

</IRS>