XML search query grammar
The grammar for XML search is based on a subset of the XPath language, which is defined by Extended Backus-Naur Form (EBNF) grammar. Queries that do not conform to the supported grammar are rejected by the query parser.
The EBNF grammar has been simplified in the following ways by:
- Disallowing absolute path names in predicate expressions
- Recognizing only one axis (tag) and only in the forward direction
- Applying additional semantic restrictions to the use of the wildcard character
- Requiring that the namespace declaration is specified in the search string before any usage, implied or explicit, of the namespace. If the namespace declaration is not included, namespaces are not considered in the search.
- Requiring that relative path expressions have a tag or attribute
name included in the expression. The query
'/'
to select the root node and the query'//'
to select all nodes are not valid expressions.
The following table shows the supported grammar in EBNF notation.
Symbol | Production |
---|---|
XMLQuery ::= | QueryPrefix NameSpaceDeclaration QueryString
| QueryPrefix QueryString |
QueryPrefix ::= | @xmlxp: |
QueryString ::= | "'" PathExpr "'" |
PathExpr ::= | RelativePathExpr
| "/" RelativePathExpr? | "//" RelativePathExpr |
RelativePathExpr ::= | StepExpr ( ( "/" | "//" ) StepExpr )* |
StepExpr ::= | ( "." | AbbrevForwardStep ) Predicate? |
AbbrevForwardStep ::= | "@"? (QName | "*") |
Predicate ::= | "[" PredicateExpr "]" |
PredicateExpr ::= | Expr
| PredicateExpr ( "and" | "or" ) | "(" PredicateExpr ")" |
Expr ::= | ComparisonExpr | ContainmentExpr |
ComparisonExpr ::= | PathExpr ComparisonOp Literal |
ComparisonOp ::= | "=" | "<" | ">" | "!=" | "<=" | ">=" |
Literal ::= | StringLiteral | NumericLiteral | DateLiteral |
ContainmentExpr ::= | PathExpr "contains" "(" StringLiteral ")"
| PathExpr "excludes" "(" StringLiteral ")" |
StringLiteral ::= | "\"" [^"]* "\""
| "'" [^']* "'" |
DateLiteral ::= | "xs:date(\"" xmlDate "\")"
| "xs:dateTime(\"" xmlDateTime "\")" |
xmlDate ::= | yyyy"-"mm"-"dd |
xmlDateTime ::= | yyyy"-"mm"-"dd [T] hh":"mm":"ss"."uuuuuu |
NameSpaceDeclaration ::= | defaultNameSpace (NameSpacePrefixDeclaration)* |
defaultNameSpace ::= | “declare default element namespace
“ StringLiteral “;” |
NameSpacePrefixDeclaration ::= | “declare namespace” NameSpacePrefix “=”
StringLiteral “;” |
NameSpacePrefix ::= | [^”:]+ |