Sybase Technical Library - Product Manuals Home
[Search Forms] [Previous Section with Hits] [Next Section with Hits] [Clear Search] Expand Search

Empty elements [Table of Contents] Chapter 4 XML Mapping Functions

XML Services in Adaptive Server Enterprise

[-] Chapter 3 XML Language and XML Query Language
[-] XML Query Language

XML Query Language

XML Services supports a subset of the standard XPath Language. That subset is defined by the syntax and tokens in the following section.

XPath-supported syntax and tokens

XML Services supports the following XPath syntax:

xpath::= or_expr
or_expr::= and_expr | and_expr TOKEN_OR or_expr
and_expr::= union_expr | union_expr TOKEN_AND and_expr
union_expr::= intersect_expr
      | intersect_expr TOKEN_UNION union_expr
intersect_expr::= comparison_expr
      | comparison_expr TOKEN_INTERSECT intersect_expr
comparison_expr::= range_exp
      | range_expr general_comp comparisonRightHandSide
general_comp::= TOKEN_EQUAL  | TOKEN_NOTEQUAL
      | TOKEN_LESSTHAN  | TOKEN_LESSTHANEQUAL
      | TOKEN_GREATERTHAN  | TOKEN_GREATERTHANEQUAL
range_expr::= unary_expr  | unary_expr TOKEN_TO unary_expr
unary_expr::= TOKEN_MINUS path_expr
      | TOKEN_PLUS path_expr
      | path_expr
comparisonRightHandSide::=  literal
path_expr::= relativepath_expr  | TOKEN_SLASH
      | TOKEN_SLASH   relativepath_expr
      | TOKEN_DOUBLESLASH   relativepath_expr
 relativepath_expr::= step_expr
      | step_expr TOKEN_SLASH relativepath_expr
      | step_expr TOKEN_DOUBLESLASH relativepath_expr
step_expr::= forward_step predicates
      | primary_expr predicates    
      | predicates
primary_expr::= literal
forward_step::= abbreviated_forward_step
abbreviated_forward_step::= name_test
      | TOKEN_ATRATE name_test
      | TOKEN_PERIOD
name_test::= q_name  | wild_card| text test
text_test ::= TOKEN_TEXT TOKEN_LPAREN TOKEN_RPAREN
literal::= numeric_literal  | string_literal
wild_card::= TOKEN_ASTERISK
q_name::= TOKEN_ID
string_literal::= TOKEN_STRING 
numeric_literal::= TOKEN_INT  | TOKEN_FLOATVAL|
      | TOKEN_MINUS TOKEN_INT 
      | TOKEN_MINUSTOKEN_FLOATVAL
predicates::= 
      | TOKEN_LSQUARE expr TOKEN_RSQUARE predicates
      | TOKEN_LSQUARE expr TOKEN_RSQUARE 

The following tokens are supported by the XML Services subset of XPath:

APOS ::= '''
DIGITS ::= [0-9]+
NONAPOS ::= '^''
NONQUOTE ::= '^"'
NONSTART ::= LETTER | DIGIT | '.' | '-' | '_' | ':'
QUOTE ::= '"'
START ::= LETTER | '_'
TOKEN_AND ::= 'and'
TOKEN_ASTERISK  ::= '*'
TOKEN_ATRATE  ::= '@            '
TOKEN_COMMA ::= ','
TOKEN_DOUBLESLASH  ::= '//'
TOKEN_EQUAL ::=  '=' 
TOKEN_GREATERTHAN ::=  '>' 
TOKEN_GREATERTHANEQUAL ::=  '>=' 
TOKEN_INTERSECT ::=   'intersect'
TOKEN_LESSTHAN ::= '<' 
TOKEN_LESSTHANEQUAL ::= '<=' 
TOKEN_LPAREN  ::= '('
TOKEN_LSQUARE  ::= '['
TOKEN_MINUS  ::= '-'
TOKEN_NOT ::= 'not'
TOKEN_NOTEQUAL ::= '!=' 
TOKEN_OR ::= 'or'
TOKEN_PERIOD  ::= '.'
TOKEN_PLUS  ::= '+' 
TOKEN_RPAREN  ::= ')'
TOKEN_RSQUARE  ::= ']'
TOKEN_SLASH  ::= '/'
TOKEN_TO ::= 'to                '
TOKEN_UNION ::= '|'  | 'union'
TOKEN_ID  ::= START [NONSTART...]
TOKEN_FLOATVAL  ::= DIGITS | '.'DIGITS | DIGITS'.'DIGITS
TOKEN_INT  ::= DIGITS
TOKEN_STRING  ::=        
       QUOTE NONQUOTE... QUOTE
      | APOS NONAPOS... APOS
TOKEN_TEXT ::=  'text'

XPath operators and functions

This section specifies the XPath subset supported by the XML processor.

XPath basic operators

Table 3-1 shows the supported basic XPath operators.

Table 3-1: XPath basic operators

Operator

Description

/

Path (Children): the child operator ('/') selects from immediate children of the left-side collection.

//

Descendants: the descendant operator ('//') selects from arbitrary descendants of the left-side collection.

*

Collecting element children: an element can be referenced without using its name by substituting the '*' collection

@

Attribute: attribute names are preceded by the '@' symbol

[]

Filter: You can apply constraints and branching to any collection by adding a filter clause '[ ]' to the collection. The filter is analogous to the SQL where clause with any semantics. The filter contains a query within it, called the sub-query. If a collection is placed within the filter, a Boolean "true" is generated if the collection contains any members, and a "false" is generated if the collection is empty.

[n]

Index: index is mainly use to find a specific node within a set of nodes. Enclose the index within square brackets. The first node is index 1.

[-n]

Backtrack index: return the element that is n-1 units from the last element. -1 means the last element, -2 is the next to last element.

[m to n]

Subscript: returns elements m through n, where m is the first index and n is the last index.

text()

Selects the text nodes of the current context node.

XPath set operators

, shows the supported XPath set operators.

Table 3-2: XPath set operators

Operator

Description

union, |

Union: union operator (shortcut is '|') returns the combined set of values from the query on the left and the query on the right. Duplicates are filtered out and resulting list is sorted in document order.

intersect

Intersection: intersect operator returns the set of elements in common between two sets.

( )

Group: you can use parentheses to group collection operators.

. (dot)

Period: dot term is evaluated with respect to a search context. The term evaluates to a set that contains only the reference node for this search context.

Boolean Operators =>

Boolean expressions can be used within subqueries.

and

Boolean "and".

or

Boolean "or".

XPath comparison operators

Table 3-3 shows the supported XPath comparison operators.

Table 3-3: XPath comparison operators

Operator

Description

=

equality

!=

non-equality

<

less than

>

greater than

>=

less than equal

<=

greater than equal


Empty elements [Table of Contents] Chapter 4 XML Mapping Functions