XMLQUERY is a SQL/XML operator that you can use to query XML values in SQL.
The XMLQUERY operator has two arguments, an XML query expression and a Derby XML value.
XMLQUERY ( xquery-string-literal PASSING BY REF xml-value-expression [ RETURNING SEQUENCE [ BY REF ] ] EMPTY ON EMPTY )
The result of the XMLQUERY operator is a value of type XML. The result represents a sequence of XML nodes or values. Atomic values, such as strings, can be part of the result sequence. The result of an XMLQUERY operator is not guaranteed to represent a well-formed XML document and it might not be possible to insert the result of an XMLQUERY operator into an XML column. To store the result in an XML column, the result must be a sequence with exactly one item in the sequence and the item must be a well-formed document node. The result can be viewed only in serialized form by explicitly using the XMLSERIALIZE operator.
SELECT ID, XMLSERIALIZE( XMLQUERY('//student[@age>20]' PASSING BY REF xcol EMPTY ON EMPTY) AS VARCHAR(50)) FROM x_tableThe result set for this query contains a row for every row in x_table, regardless of whether or not the XMLQUERY operator actually returns results.
SELECT ID, XMLSERIALIZE( XMLQUERY('string(//student[text() = "BC"]/@age)' PASSING BY REF xcol EMPTY ON EMPTY) AS VARCHAR(50)) FROM x_table WHERE XMLEXISTS('//student[text() = "BC"]' PASSING BY REF xcol)The result set for this query contains a row for only the rows in x_table that have a student whose name is BC.
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 XMLQUERY 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.