xql, oql and sql xia tang sixin qian shijun shen feb 18, 2000

26
XQL, OQL and SQL Xia Tang Sixin Qian Shijun Shen Feb 18, 2000

Upload: scot-young

Post on 13-Jan-2016

221 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: XQL, OQL and SQL Xia Tang Sixin Qian Shijun Shen Feb 18, 2000

XQL, OQL and SQL

Xia Tang

Sixin Qian

Shijun Shen

Feb 18, 2000

Page 2: XQL, OQL and SQL Xia Tang Sixin Qian Shijun Shen Feb 18, 2000

XQL (XML Query Language)

XQL is a notation for addressing and

filtering the elements and text of XML

documents.(W3C)

Page 3: XQL, OQL and SQL Xia Tang Sixin Qian Shijun Shen Feb 18, 2000

XQL (XML Query Language)

• XQL is designed specifically for XML documents.

• XQL is a proposed extension to the XSL pattern syntax.

• XQL is concise, simple, and powerful.

Page 4: XQL, OQL and SQL Xia Tang Sixin Qian Shijun Shen Feb 18, 2000

What is an XML Query?Questions XQL

What is a database? The database is a set of one ormore XML documents.

What is the input to aquery?

A query is given a list of inputnodes from one or moredocuments.

What is the result of aquery?

The result of a query is a list ofXML document nodes, which mayserve as the basis for furtherqueries.

Page 5: XQL, OQL and SQL Xia Tang Sixin Qian Shijun Shen Feb 18, 2000

Approaches

• Using Document Object Model subtrees as the basis for a query.

• Using data dictionaries or repository directory structures to identify nodes to be queried.

• Using a URL identify documents.

Page 6: XQL, OQL and SQL Xia Tang Sixin Qian Shijun Shen Feb 18, 2000

XQL notations. Selects the current node.

.. Selects the parent of current node.

/ Selects the document node.

a[expr]Select only those nodes matching a which also

Satisfy the expression expr.

a[n] Selects the nth matching node matching a

a/b For each node matching a, add the nodes matching b to the result.

a//b For each node matching a, add the descendant nodes matching b to the result.

//b Returns elements in the entire document matching b.

a/b All nodes matching a or b.

Page 7: XQL, OQL and SQL Xia Tang Sixin Qian Shijun Shen Feb 18, 2000

XQL notation

• A simple string is interpreted as an element name.

Example:

table

this query specification returns all <table> elements.

Page 8: XQL, OQL and SQL Xia Tang Sixin Qian Shijun Shen Feb 18, 2000

XQL notation

• The child operator “/” indicates hierarchy.

Front/author

This query returns <author> elements that are children of <front> elements.

Page 9: XQL, OQL and SQL Xia Tang Sixin Qian Shijun Shen Feb 18, 2000

XQL notation

• The equals operator ‘=’.

The content of an element or the value of an attribute may be specified using ‘=’.

Front/author=‘Bob’

return all authors with the name ‘Bob’ that are

children of the <front> element.

Page 10: XQL, OQL and SQL Xia Tang Sixin Qian Shijun Shen Feb 18, 2000

XQL notation

• Attribute names are preceded by the '@' ,

They are treated as children of the elements to

which they belong.

Front/author/address/@type=‘email’

Find the type attribute with ‘email’ for all

address elements

Page 11: XQL, OQL and SQL Xia Tang Sixin Qian Shijun Shen Feb 18, 2000

XQL notation

• The descendant operator ‘//’ indicates any number of intervening levels.

Bookstore//title

Find all title elements, one or more levels

deep in the bookstore (arbitrary descendants).

Page 12: XQL, OQL and SQL Xia Tang Sixin Qian Shijun Shen Feb 18, 2000

XQL notation

• The filter operator ‘[]’ filters the set of nodes to its left based on the conditions inside the brackets.

Front/author/address[@type=‘email’]

returns addresses: each of these addresses

must have a attribute called ‘type’ with the

value ‘email’.

Page 13: XQL, OQL and SQL Xia Tang Sixin Qian Shijun Shen Feb 18, 2000

XQL notation

• Brackets’[]’ are also used for subscripts, which indicate position within a document.

• Conditions and subscripts, both uses of brackets may occur in the same query.

Section[@level=‘3’][1 to 2]

It returns the first three ‘level 3’ sections.

Page 14: XQL, OQL and SQL Xia Tang Sixin Qian Shijun Shen Feb 18, 2000

Example<?xml version="1.0"?>

<invoicecollection> <invoice> <customer> Bob, CA

</customer> <entries n=2> ………. </entries>

</invoice><invoice>

<customer> John, CA </customer> <entries n=2> ………. </entries>

</invoice></invoicecollection>

Query: //customer Result: <xql:result> <customer>

Bob,CA </customer> <customer>

John,CA </customer> </xql:result>

Page 15: XQL, OQL and SQL Xia Tang Sixin Qian Shijun Shen Feb 18, 2000

XQL Expressions

• Termsnode Selects all child elements with

node name is node.* Selects all child elements.@attr Selects the attribute attr.@* Selects all attributes.node() Matches an element node.text() Matches a text node.comment() Matches a comment.pi() Matches a processing instruction node.

Page 16: XQL, OQL and SQL Xia Tang Sixin Qian Shijun Shen Feb 18, 2000

XQL Expressions

• Namespaces and names

In attribute names, the attribute prefix comes

before the namespace prefix.

my:book

Find all book elements with the prefix 'my'.

Page 17: XQL, OQL and SQL Xia Tang Sixin Qian Shijun Shen Feb 18, 2000

XQL Expression

• ComparisonsA set of binary comparison operators is available for

comparing numbers and strings and returning

Boolean results.

<, <=, > and >= are allowed short cuts for $lt$, $le$,

$gt$ and $ge$.

Page 18: XQL, OQL and SQL Xia Tang Sixin Qian Shijun Shen Feb 18, 2000

XQL Expressions

• Boolean and Set Operators

Boolean expressions can be used within subqueries. Multiple conditions may be combined using Boolean operators and set operators.

Page 19: XQL, OQL and SQL Xia Tang Sixin Qian Shijun Shen Feb 18, 2000

XQL Expressions

• Grouping operator ‘()’.

Parentheses ‘()’ can be used to group

collection operators for clarity or where the

normal precedence is inadequate to express an

operation.

Page 20: XQL, OQL and SQL Xia Tang Sixin Qian Shijun Shen Feb 18, 2000

XQL Expressions• Functions (collection functions)

Taken from XSL pattern languagetext() The text contained within the element. This concatenates the text of

all of the element's descendants. It does not include the tag names or any attribute values, comment values, etc. It trims the string as discussed in text(). (Returns a string.)

value() Returns a type cast version of the value of an element. (See

Datatypes) If data typing is not supported or a data type is

not provided, returns the same as text().

nodeType() Returns a number to indicate the type of the node:

element 1; attribute 2; text 3; PI 7; comment 8;

document 9.

nodeName() The tag name of the node, including the namespace prefix. (Returns a string.)

Page 21: XQL, OQL and SQL Xia Tang Sixin Qian Shijun Shen Feb 18, 2000

XQL Expression

• Collection Function

search context of the Invocation instance;

evaluates to a subset of the search context.

• Pure Function

Ignore the search context;

evaluates to either a constant value or to a value that depends only on the function's parameters.

Page 22: XQL, OQL and SQL Xia Tang Sixin Qian Shijun Shen Feb 18, 2000

XQL Expressions

• Extensible Functions

To allow user-defined functions to be written,

XQL provides a function called “function()”.

• Joins

To allow subtrees from one data source to be

inserted into another document subtree,

subject to the join conditions.

Page 23: XQL, OQL and SQL Xia Tang Sixin Qian Shijun Shen Feb 18, 2000

XQL Expressions

• Renaming Operator “->”

The nodes in a list may be renamed using the

renaming operator. “->” may also be used to

adjust namespaces in query results.

Page 24: XQL, OQL and SQL Xia Tang Sixin Qian Shijun Shen Feb 18, 2000

Precedence of OperatorsProduction Operator(s)

Grouping ( )

Filter [ ]

Subscript [ ]

Bang !

Path / //

Comparison = != < <= > >= $eq$ $ne$ $lt$ $le$ $gt$ $ge$

$ieq$ $ine$ $ilt$ $ile$ $igt$ $ige$

Intersection $intersect$

Union $union$ |

Negation $not$

Conjunction $and$

Disjunction $or$

Page 25: XQL, OQL and SQL Xia Tang Sixin Qian Shijun Shen Feb 18, 2000

XQL’s important key features

• XML documents can be queried like a database;

• XQL is based on of XML so it allows for powerful queries to be simply expressed;

• It uses a string syntax that allows queries to be used in URL’s or embedded in attributes.

Page 26: XQL, OQL and SQL Xia Tang Sixin Qian Shijun Shen Feb 18, 2000

Links

http://www.w3.org/TandS/QL/QL98/pp/xql.html

http://www.w3.org/Style/XSL/Group/1998/09/XQL-proposal.html