1.1.1

Table Of Contents
In the x_table table, to search the XML column xcol and return the ages for any students named BC, use
the following statement:
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.
Usage note
SQLFire 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 on page 634 for details.
XMLSERIALIZE operator
XMLSERIALIZE is a SQL/XML operator that you can use to convert an XML type to a character type. There
is no other way to convert the type of a SQLFire XML value.
Attention: Serialization is performed based on the SQL/XML serialization rules. These rules, combined
with the fact that SQLFire supports only a subset of the XMLSERIALIZE syntax, dictate that the results
of an XMLSERIALIZE operation are not guaranteed to be in-tact copies of the original XML text. For
example, assume that [xString] is a textual representation of a well-formed XML document. You
issue the following statements:
INSERT INTO x_table (id, xcol)
VALUES (3, XMLPARSE(DOCUMENT '[xString]' PRESERVE WHITESPACE));
SELECT id, XMLSERIALIZE(xcol AS VARCHAR(100))
FROM x_table WHERE id = 3;
There is no guarantee that the result of the XMLSERIALIZE operator will be identical to the original
[xString] representation. Certain transformations can occur as part of XMLSERIALIZE processing,
and those transformations are dened in the SQL/XML specication. In some cases the result of
XMLSERIALIZE might actually be the same as the original textual representation, but that is not
guaranteed.
When an XMLSERIALIZE operator is specied as part of the top-level result set for a query, the result
can be accessed from JDBC by using whatever JDBC getXXX methods are allowed on the
string-data-type argument that is included in the XMLSERIALIZE syntax. If you attempt to select
the contents of an XML value from a top-level result set without using the XMLSERIALIZE operator,
SQLFire throws an error. SQLFire does not implicitly serialize XML values.
Syntax
XMLSERIALIZE ( xml-value-expression AS string-data-type )
Can be any Derby XML value, including an XML result sequence generated by
the XMLQUERY operator. The xml-value-expression argument cannot
be a parameter.
xml-value-expression
593
SQL Language Reference