View
219
Download
2
Tags:
Embed Size (px)
Citation preview
4/15/2002 Bo Du 1
- Bo Du, April 15, 2002
XML - QL
A Query Language for XML
4/15/2002 Bo Du 3
OUTLINE Introduction
Examples in XML-QL
A Data Model for XML
Advanced Examples in XML-QL
Extensions and Open Issues
Summary
4/15/2002 Bo Du 4
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 DTDs?
Integration : How will XML data from multiple XML sources be integrated?
Conversion of data between relational or OO to XML
4/15/2002 Bo Du 5
Useful References http://www.w3.org/XML/Query http://www.w3.org/TR/NOTE-xml-ql/ http://www.ibiblio.org/xql/ http://groups.yahoo.com/group/xml-dev/ ……
4/15/2002 Bo Du 6
Is this X?L a standard?
NO!It is a submission to the World Wide Web Consortium. It is intended for review and
comment by W3C members and is subject to change!!!
4/15/2002 Bo Du 7
What does XML-QL do exactly?
Extraction - of data pieces from XML documents
Transformation - Map XML data between different DTDs
Integration/Combination of XML data from different sources
4/15/2002 Bo Du 8
How will data be extracted from large XML documents?
4/15/2002 Bo Du 9
Data Transformation
4/15/2002 Bo Du 10
Data Integration
4/15/2002 Bo Du 11
Requirements for the XML Query Language Selection and extraction Preserve structure Reduction Restructuring Join
(more detail in next section)
4/15/2002 Bo Du 12
OUTLINE Introduction
Examples in XML-QL
A Data Model for XML
Advanced Examples in XML-QL
Extensions and Open Issues
Summary
4/15/2002 Bo Du 13
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>
4/15/2002 Bo Du 14
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)>
4/15/2002 Bo Du 15
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
4/15/2002 Bo Du 16
Basic Examples(contd.)
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
4/15/2002 Bo Du 17
Results of our first queryThe output is in XML form:
<lastname> Date </lastname>
<lastname> Darwen </lastname>
<lastname> Date </lastname>
4/15/2002 Bo Du 18
Use the current XML to construct a new XML structure<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>
4/15/2002 Bo Du 19
Construct new XML data (Query)WHERE <book>
<publisher> <name> Addison-Wesley </></>
<title> $t </>
<author> $a </>
</> IN "www.a.b.c/bib.xml"
CONSTRUCT <result>
<author> $a </>
<title> $t </>
</>
4/15/2002 Bo Du 20
Construct 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 OR Databases</title>
</result>
4/15/2002 Bo Du 21
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 </>
</>
4/15/2002 Bo Du 22
Reduction of previous slideWhere
<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 </>
4/15/2002 Bo Du 23
Another way: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 </>
</>
4/15/2002 Bo Du 24
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>
4/15/2002 Bo Du 25
OUTLINE Introduction
Examples in XML-QL
A Data Model for XML
Advanced Examples in XML-QL
Extensions and Open Issues
Summary
4/15/2002 Bo Du 26
XML Data model
XML Graph Syntax for Data Mapping of XML graphs into XML
documents Element identities an ID references ……
(talked in previous presentations)
4/15/2002 Bo Du 27
OUTLINE Introduction
Examples in XML-QL
A Data Model for XML
Advanced Examples in XML-QL
Extensions and Open Issues
Summary
4/15/2002 Bo Du 28
Advanced examples in XML-QL Tag Variables Regular - path Expressions Transforming XML data Integrating from multiple XML sources Functions definitions and DTDs External functions Ordered model - Sorting, Indexing
4/15/2002 Bo Du 29
Tag variablesWHERE < $p > -- $p can be {article, book}
<title> $t </>
<year>1995 </>
< $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
4/15/2002 Bo Du 30
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>
4/15/2002 Bo Du 31
payroll.xml<Payroll>
<person><ssn>100-00-0001</ssn><name>J. Doe</name><salary>35000</salary> </person>
<person><ssn>100-00-0002</ssn><name>M. Smith</name><salary>73000</salary> </person>
<person><ssn>100-00-0003</ssn><name>R. Johnson</name><salary>1400000</salary> </person>
<person><ssn>100-00-0004</ssn><name>P. Kent</name><salary>33000</salary> </person>
</Payroll>
4/15/2002 Bo Du 32
taxpayers.xml<IRS>
<taxpayer> <ssn>100-00-0001</ssn><income>35000</income><taxes>7000</taxes> </taxpayer>
<taxpayer> <ssn>100-00-0002</ssn><income>55000</income><taxes>3000</taxes> </taxpayer>
<taxpayer><ssn>100-00-0003</ssn><income>1430000</income><taxes>25000</taxes> </taxpayer>
<taxpayer> <ssn>100-00-0005</ssn><income>120000</income><taxes>30000</taxes> </taxpayer>
</IRS>
4/15/2002 Bo Du 33
Integrating data from multiple XML sourcesWHERE <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 at
taxpayer.xmlCONSTRUCT <result> $n $i </>
4/15/2002 Bo Du 34
Integration result<result>
<income>35000</income> <name>J. Doe</name>
</result><result>
<income>55000</income><name>M.Smith</name>
</result><result>
<income>1430000</income> <name>R. Johnson</name>
</result>
4/15/2002 Bo Du 35
Functions definitions and DTDsfunction 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 </> </>}
4/15/2002 Bo Du 36
Functions definitions and DTDs (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 ….
}
4/15/2002 Bo Du 37
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 </> </>
</>
4/15/2002 Bo Du 38
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.
4/15/2002 Bo Du 39
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
4/15/2002 Bo Du 40
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 </>
4/15/2002 Bo Du 41
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>
4/15/2002 Bo Du 42
OUTLINE Introduction
Examples in XML-QL
A Data Model for XML
Advanced Examples in XML-QL
Extensions and Open Issues
Summary
4/15/2002 Bo Du 43
Extensions and open issues:
Entities User-defined predicates String regular expressions Name spaces Aggregates XML syntax Extensions to other XML-related standard
4/15/2002 Bo Du 44
OUTLINE Introduction
Examples in XML-QL
A Data Model for XML
Advanced Examples in XML-QL
Extensions and Open Issues
Summary
4/15/2002 Bo Du 45
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
4/15/2002 Bo Du 46
End
???…