background image
<< XMLEXISTS operator | PRESERVE WHITESPACE >>

XMLPARSE operator

<< XMLEXISTS operator | PRESERVE WHITESPACE >>
Derby Reference Manual
146
When evaluation of the specified query expression against the specified xml-value
returns an empty sequence.
The XMLEXISTS operator does not return the actual results from the evaluation of the
query. You must use the XMLQUERY operator to retrieve the actual results.
Since the result of the XMLEXISTS operator is an SQL boolean data type, you can use
the XMLEXISTS operator wherever a boolean function is allowed. For example, you
can use the XMLEXISTS operator as a check constraint in a table declaration or as a
predicate in a WHERE clause.
Examples
In the
x_table
table, to determine if the
xcol
XML column for each row has an element
called
student
with an
age
attribute equal to 20, use this statement:
SELECT id, XMLEXISTS('//student[@age=20]' PASSING BY REF xcol)
FROM x_table
In the
x_table
table, to return the ID for every row whose
xcol
XML column is non-null
and contains the element
/roster/student
, use this statement:
SELECT id FROM x_table WHERE XMLEXISTS('/roster/student' PASSING BY REF
xcol)
You can create the
x_table
table with a check constraint that limits which XML values
can be inserted into the
xcol
XML column. In this example, the constraint is that the
column has at least one
student
element with an
age
attribute with a value that is less
than 25. To create the table, use this statement:
CREATE TABLE x_table ( id INT, xcol XML CHECK (XMLEXISTS ('//student[@age
< 25]
' PASSING BY REF xcol)) )
Usage note
Derby requires that a JAXP parser (such as Apache Xerces) and Apache Xalan are listed
in the Java classpath for the XML functions to work. If either the JAXP parser or Xalan
is missing from the classpath, attempts to use the XMLEXISTS operator will result in an
error. In some situations, you may need to take steps to place the parser and Xalan in
your classpath. See "XML data types and operators" in the Derby Developer's Guide for
details.
XMLPARSE operator
XMLPARSE is a SQL/XML operator that you use to parse a character string expression
into a Derby XML value.
You can use the result of this operator temporarily or you can store the result
permanently in Derby XML columns. Whether temporary or permanent, you can use
the XML value as an input to the other Derby XML operators, such as
XMLEXISTS
and
XMLQUERY
.
Syntax
XMLPARSE (DOCUMENT string-value-expression PRESERVE WHITESPACE)
DOCUMENT
Required keyword that describes the type of XML input that Derby can parse. Derby
can only parse string expressions that constitute well-formed XML documents. This
is because Derby uses a JAXP parser to parse all string values. The JAXP parser
expects the string-value-expression to constitute a well-formed XML document. If