Download presentation
Presentation is loading. Please wait.
Published byScot Young Modified over 9 years ago
1
XQL, OQL and SQL Xia Tang Sixin Qian Shijun Shen Feb 18, 2000
2
XQL (XML Query Language) XQL is a notation for addressing and filtering the elements and text of XML documents.(W3C)
3
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.
4
What is an XML Query?
5
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.
6
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/bFor each node matching a, add the nodes matching b to the result. a//bFor each node matching a, add the descendant nodes matching b to the result. //bReturns elements in the entire document matching b. a/bAll nodes matching a or b.
7
XQL notation A simple string is interpreted as an element name. Example: table this query specification returns all elements.
8
XQL notation The child operator “/” indicates hierarchy. Front/author This query returns elements that are children of elements.
9
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 element.
10
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
11
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).
12
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’.
13
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.
14
Example Bob, CA ………. John, CA ………. Query: //customer Result: Bob,CA John,CA
15
XQL Expressions Terms node 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.
16
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'.
17
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$.
18
XQL Expressions Boolean and Set Operators Boolean expressions can be used within subqueries. Multiple conditions may be combined using Boolean operators and set operators.
19
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.
20
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.)
21
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.
22
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.
23
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.
24
Precedence of Operators Production 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$
25
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.
26
Links http://www.w3.org/TandS/QL/QL98/pp/xql.html http://www.w3.org/Style/XSL/Group/1998/09/X QL-proposal.html
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.