900 likes | 1.08k Views
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:
E N D
XML - QLA 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 XML-QL
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 XML-QL
What Does XML-QL do ? Extraction - of data pieces from XML documents Transformation - Map XML data between different DTDs Integration/Combinationof XML data from different sources XML-QL
DataTransformation How will XML data be exchanged between user communities using different but related DTD's? XML-QL
Data Integration XML-QL
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. XML-QL
Requirements for a query language for XML • Selection and extraction • Preserve structure. • Reduction • Restructuring • Join (will be shown in the first part) XML-QL
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) XML-QL
Outline • Introduction • Examples in XML-QL • A Data Model for XML • Advanced Examples in XML-QL • Extensions and Open Issues • Summary XML-QL
Class Number – cs 401 Class- web and xml Instructor – Sanjay Madria Lesson Title - XML-QL XML-QL
BIB . DTD <!ELEMENTbook (author+, title, publisher)> <!ATTLIST book year CDATA> <!ELEMENTarticle (author+, title, year?, (shortversion|longversion))> <!ATTLISTarticle type CDATA> <!ELEMENTpublisher (name, address)> <!ELEMENT author (firstname?, lastname)> XML-QL
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 XML-QL
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 XML-QL
Result of first query: The output is in XML form: <lastname> Date </lastname> <lastname>Darwen </lastname> <lastname> Date </lastname> XML-QL
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 </> </> XML-QL
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> XML-QL
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> XML-QL
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 </> </> XML-QL
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 </> XML-QL
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 </> </> XML-QL
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> XML-QL
Joining element by values: WHERE <article> <author> <firstname> $fn </> -- firstname $f <lastname> $ln </> -- firstname $l </> </> CONTENT_AS$aIN"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 </> XML-QL
ELEMENT_AS Vs. CONTENT_AS: WHERE <article> <author> <firstname> $fn </> -- firstname $fn <lastname> $ln </> -- firstname $ln </> </> ELEMENT_AS$aIN"www.a.b.c/bib.xml”, … CONSTRUCT$a-- No need for <article> …. </> XML-QL
Outline • Introduction • Examples in XML-QL • A Data Model for XML • Advanced Examples in XML-QL • Extensions and Open Issues • Summary XML-QL
A data model for XML • XML : data format syntax • Query operations assume data model • XML 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 XML-QL
XML graph for example XML book elements root book book (year=“1998”) (year=“1995”) author title author title publisher author publisher Foundations for ... lastname lastname An introduction … name lastname name Date Datwen Addison-Wesley Addison-Wesley Date XML-QL
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 IDID#REQUIRED> <!ATTLIST article auther IDREFS#IMPLIED> XML-QL
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> XML-QL
XML graph including ID & IDREFS root article person person author first name first name last name title year last name 1995 John Smith XML-QL
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 </> XML-QL
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> oid1 catalogue oid2 book author publication=b1 author=a1 author a1 b1 publication Memories... 1997 Arthur Golden XML-QL
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. XML-QL
Scalar Values: (cont) <title> <CDATA>A trip to </CDATA> <titlepart> <CDATA> The Moon</CDATA> </titlepart> </title> title XML graph -> CDATA titlepart “A trip to” CDATA “The Moon” XML-QL
ElementOrder • 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. XML-QL
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. XML-QL
Outline • Introduction • Examples in XML-QL • A Data Model for XML • Advanced Examples in XML-QL • Extensions and Open Issues • Summary XML-QL
Advanced examples in XML-QL • Tag Variables • Regular - path Expressions • Transforming XML data • Integrating from multiple XML sources • No schema required • Functions definitions and DTD’s • External functions • Ordered model - Sorting, Indexing XML-QL
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", $eIN{author, editor} CONSTRUCT < $p > <title> $t </> < $e > Date </> </> All publications published in 1995 in which Date is either an author, or an editor XML-QL
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> XML-QL
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: <!ELEMENTpart (name brand part*)> <!ELEMENTname CDATA> <!ELEMENTbrand CDATA> XML-QL
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 </> XML-QL
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 </> </> </> </> • ... XML-QL
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 </> XML-QL
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. XML-QL
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> XML-QL
Transforming XML data • Translate 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. XML-QL
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 </> </> XML-QL
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> XML-QL