# XML data type

The XML data type is used for Extensible Markup Language (XML) documents.

The XML data type is used:

- To store XML documents that conform to the SQL/XML definition of a well-formed XML(DOCUMENT(ANY)) value.
- Transiently for XML(SEQUENCE) values, that might not be well-formed XML(DOCUMENT(ANY)) values.

Note: For an application to retrieve, update, query, or otherwise access an XML data value, the application must have classes for a JAXP parser and for Xalan in the classpath. Derby issues an error if either the parser or Xalan is not found.

Because none of the JDBC-side support for SQL/XML is implemented in Derby, it is not possible to bind directly into an XML value or to retrieve an XML value directly from a result set using JDBC. Instead, you must bind and retrieve the XML data as Java strings or character streams by explicitly specifying the appropriate XML operators, XMLPARSE and XMLSERIALIZE, as part of your SQL queries.

#### Syntax

    XML

#### Corresponding compile-time Java type

None

The Java type for XML values is java.sql.SQLXML. However, the java.sql.SQLXML type is not supported by Derby.

#### JDBC metadata type (java.sql.Types)

None

The metadata type for XML values is SQLXML. However, the SQLXML type is not supported by Derby.

To retrieve XML values from a Derby database using JDBC, use the XMLSERIALIZE operator in the SQL query. For example:

    SELECT XMLSERIALIZE (xcol as CLOB) FROM myXmlTable

Then retrieve the XML value by using the getXXX method that corresponds to the target serialization type, in this example CLOB data types.
To store an XML value into a Derby database using JDBC, use the XMLPARSE operator in the SQL statement. For example:

    INSERT INTO myXmlTable(xcol) VALUES XMLPARSE(
        DOCUMENT CAST (? AS CLOB) PRESERVE WHITESPACE)

Then use any of the setXXX methods that are compatible with String types, in this example use the PreparedStatement.setString or PreparedStatement.setCharacterStream method calls to bind the operator.
Parent topic: Data types
Related concepts
Built-In type overview
Numeric types
Related reference
Data type assignments and comparison, sorting, and ordering
BIGINT
BLOB
CHAR
CHAR FOR BIT DATA
CLOB
DATE
DECIMAL
DOUBLE
DOUBLE PRECISION
FLOAT
INTEGER
LONG VARCHAR
LONG VARCHAR FOR BIT DATA
NUMERIC
REAL
SMALLINT
TIME
TIMESTAMP
VARCHAR
VARCHAR FOR BIT DATA