Download XML Query Language --XQL

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Clusterpoint wikipedia , lookup

Database model wikipedia , lookup

Relational algebra wikipedia , lookup

Relational model wikipedia , lookup

Transcript
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)
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.
What is an XML Query?
Questions
XQL
What is a database?
The database is a set of one or
more XML documents.
What is the input to a
query?
A query is given a list of input
nodes from one or more
documents.
What is the result of a The result of a query is a list of
query?
XML document nodes, which may
serve as the basis for further
queries.
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.
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.
XQL notation
• A simple string is interpreted as an element
name.
Example:
table
this query specification returns all <table> elements.
XQL notation
• The child operator “/” indicates hierarchy.
Front/author
This query returns <author> elements that are
children of <front> elements.
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.
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
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).
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’.
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.
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>
XQL Expressions
• Terms
node
*
@attr
@*
node()
text()
comment()
pi()
Selects all child elements with
node name is node.
Selects all child elements.
Selects the attribute attr.
Selects all attributes.
Matches an element node.
Matches a text node.
Matches a comment.
Matches a processing instruction node.
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'.
XQL Expression
• Comparisons
A 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$.
XQL Expressions
• Boolean and Set Operators
Boolean expressions can be used within
subqueries. Multiple conditions may be
combined using Boolean operators and set
operators.
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.
XQL Expressions
• Functions (collection functions)
Taken from XSL pattern language
text()
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.)
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.
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.
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.
Precedence of Operators
Production
Grouping
Filter
Subscript
Bang
Path
Comparison
Intersection
Union
Negation
Conjunction
Disjunction
Operator(s)
()
[]
[]
!
/ //
= != < <= > >= $eq$ $ne$ $lt$ $le$ $gt$ $ge$
$ieq$ $ine$ $ilt$ $ile$ $igt$ $ige$
$intersect$
$union$ |
$not$
$and$
$or$
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.
Links
http://www.w3.org/TandS/QL/QL98/pp/xql.html
http://www.w3.org/Style/XSL/Group/1998/09/X
QL-proposal.html