120 likes | 391 Views
XQL (XML Query Language). Jonathan Robie (Software AG) <jonathan.robie@sagus.com> Eduard Derksen (CSCIO) <enno@att.com> Peter Fankhauser (GMD-IPSI) <fankhaus@darmstadt.gmd.de> Ed Howland (DEGA) <Ed@dega.com> Gerald Huck (GMD-IPSI) <huck@darmstadt.gmd.de>
E N D
XQL (XML Query Language) Jonathan Robie (Software AG) <jonathan.robie@sagus.com> Eduard Derksen (CSCIO) <enno@att.com> Peter Fankhauser (GMD-IPSI) <fankhaus@darmstadt.gmd.de> Ed Howland (DEGA) <Ed@dega.com> Gerald Huck (GMD-IPSI) <huck@darmstadt.gmd.de> Ingo Macherius (GMD-IPSI) <macherius@darmstadt.gmd.de> Makoto Murata (Fuji Xerox) <murata@apsdc.ksp.fujixerox.co.jp> Michael Resnick (Object Design, Incorporated) <resnick@odi.com> Harald Schöning (Software AG) <harald.schoening@softwareag.de>
XQL vs. SQL • What is the database? • SQL: A set of tables • XQL: A set of one or more XML documents. • What is the query language? • SQL: A query language that uses the structure of tables as a basic model. • XQL: A query language that uses the structure of XML documents as a basic model. • What is the input to a query? • SQL: The FROM clause determines the tables which are examined by the query. • XQL: A query is given a list of input nodes from one or more documents. • What is the result of a query? • SQL: The result of a query is a table containing a set of rows; this table may serve as the basis for further queries. • XQL: The result of a query is a list of XML document nodes, which may serve as the basis for further queries.
XQL Expressions • Terms • Namespaces and Names • Comparisons • Hierarchy and Filters • Boolean and Set Operators • Grouping Operator • Sequence
XQL Expressions (cond.) • Functions • Extensible Functions • References (not incorporated into XQL) • Joins • Renaming Operator • Precedence of Operators
Learn XQL by Examples • Terms: • A simple string is interpreted as an element name: • Query example: author. • Attribute names begin with "@". • Query example: address/@type='email’. • Hierarchy: • Child operator “/” • Query example: /novel/author • Paths are described from the top down and usually the right-most element on the path is returned • Descendant operator ("//") indicates any number of intervening levels • Example: novel//address • Shows addresses anywhere within <novel>.
Learn XQL by Examples (cond.) • Filters: • Filter operator ("[ ]") filters the set of nodes to its left based on the conditions inside the brackets. • Example: novel/author/address[@type='email'] • Returns addresses: each address must have an attribute called "type" with the value "email”. • Boolean Operations and Comparisons: • Boolean operators can be used to combine conditions. • Example: • novel/author =’Tom’ [@gender='male' and @shoesize>'9EEEE'] • Set Operations: • Can be used to combine Terms or other XQL expressions. • Example: q1 union q2 (also can be written as q1 | q2) • Example: q1 intersect q2
Learn XQL by Examples (cond.) • Namespaces and Names: • Names may be associated with namespace prefixes • A namespace prefix can be declared using a variable. • Example: • b := "http://www.TwiceSoldTales.com" • //b:book • The first line declares "b" to be a variable equivalent to the namespace URI "http://www.TwiceSoldTales.com” • The second line searches for all <book> elements in this namespace. • Grouping Operator: • Useful to group results. • Example: //book {.//author} • The element to the left of the {} is used to group the results of the query within the braces.
Learn XQL by Examples (cond.) • Sequence Operators: • a before b (returns a list of all "a"s that precede a "b”) • a after b (returns a list of all "a"s that occur after a "b”) • a, b (returns a list containing all "a"s, followed by all "b"s) • XQL operators generally maintain document order. • Useful for specifying order in return lists. • Functions: • XQL provide some functions. • Example: • element(), element(‘name’) • returns elements in the context. If a name argument is supplied, returns the elements with the given name. • count()
Learn XQL by Examples (cond.) • Extensible Functions: • Allow users to write their own functions • Functions are passed the list of nodes in the current context. If the function has parameters, these are passed as strings. • The result of a function call is also a nodelist. • Example: • User can add a function that computes the average for a list of values and call it in an XQL query • average(property//price) • <xql:number> 12345.6789 </xql:number> • Renaming Operator • Nodes in a list can be renamed using renaming operator "->". • Example: //book->a:book • Rename the book into a new namespace a
Learn XQL by Examples (cond.) • References: • XSL provides "id()" function, which returns the element containing a given id. • Example: A/id(@HREF) • Return the node pointed to by an HREF attribute in an <A> element • Actually it is a join. But this syntax less complex than join. • XQL extends to incorporate any kind of link, not just ID/IDREF. • Example: A/ref(@HREF) • Function ref() returns the node (nodes) to which an XPointer or HTML HREF points • Can specify parameters to this function • Example: A/ref(@HREF, "table") • Return the referenced node only if it is a 'table" element; otherwise, will return null.
Learn XQL by Examples (cond.) • Joins: • Combine information from multiple sources to create one unified view. • Example: • /book { isbn | title | author | //review { reviewer | comments } } • Only correct when the database consists only of this one book and this one review. • /book[$i:=isbn] { isbn | title | author | //review[isbn=$i] { reviewer | comments }} • using correlation variables to restrict the reviews to those that have the same ISBN number as the book.