XML text search grammar

A subset of the XPath language, which is defined by an Extended Backus-Naur Form (EBNF) grammar, is supported by the XML search query parser. Queries that do not conform to the supported grammar are rejected by the query parser, which throws an exception.

The EBNF grammar has been simplified in the following ways by:

The following table shows the supported grammar in EBNF notation.

Table 1. Supported query 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 ::= [^”:]+

For more information about QName, see http://www.w3.org/TR/REC-xml-names/#NT-QName.

The following information about XML search queries that use XPath notation might not be obvious from the EBNF grammar notations: