XMLType
is a system-defined opaque type for handling XML data. It as predefined member functions on it to extract XML nodes and fragments.
You can create columns of XMLType
and insert XML documents into it. You can also generate XML documents as XMLType
instances dynamically using the SYS_XMLAGG SQL
function.
This chapter contains the following topics:
Table 285-1 summarizes functions and procedures of the XMLType
.
Table 285-1 XMLTYPE Subprograms
Method | Description |
---|---|
Creates a non schema based XML from the input schema based instance. |
|
Creates a schema based |
|
Static function for creating and returning an |
|
Takes a |
|
Takes a |
|
Returns the value of the |
|
Returns the value of the |
|
Returns the namespace for the top level element in a schema based document. |
|
Returns the value of the |
|
Returns the root element of the input instance. Returns |
|
Returns the XML schema URL if the input is an XML Schema based. |
|
Returns the value of the |
|
Checks if the input |
|
Returns 1 or 0 indicating if the input |
|
Checks if the input instance is schema valid according to the given schema URL. |
|
Checks if the instance has been validated against the schema. |
|
Validates the input instance according to the XML Schema. Raises error if the input instance is non-schema based. |
|
Sets the schema valid flag to avoid costly schema validation. |
|
Converts the |
|
Takes an |
|
Constructs an instance of the |
Member function. Creates a non-schema based XML document from a schema based instance.
MEMBER FUNCTION CREATENONSCHEMABASEDXML return XMLType deterministic;
Member function. Creates a schema based XMLType
instance from a non-schema based XMLType
value. It uses either the supplied SCHEMA
URL, or the SCHEMALOCATION
attribute of the instance.
MEMBER FUNCTION createSchemaBasedXML( schema IN varchar2 := NULL) return XMLType deterministic;
Parameter | Description |
---|---|
schema |
Optional XMLSchema URL used to convert the value to the specified schema. |
Static function for creating and returning an XMLType
instance. The string and CLOB
parameters used to pass in the date must contain well-formed and valid XML documents. The options are described in the following table.
Syntax | Description |
---|---|
STATIC FUNCTION createXML(
|
Creates the XMLType instance from a string. |
STATIC FUNCTION createXML(
|
Creates the XMLType instance from a CLOB . |
STATIC FUNCTION createXML (
|
This static function creates a schema-based XMLType instance using the specified schema and xml data parameters. |
STATIC FUNCTION createXML (
|
This static function creates a schema-based XMLType instance using the specified schema and xml data parameters. |
STATIC FUNCTION createXML (
|
Creates an XML instance from an instance of an user-defined type. |
STATIC FUNCTION createXML (
|
Creates an XML instance from a cursor reference. You can pass in any arbitrary SQL query as a CURSOR . |
STATIC FUNCTION createXML (
|
Creates an XML instance from ANYDATA .If the ANYDATA instance contains an ADT, the XMLType returned is the same as would be returned for a call directly on the ADT. If the ANYDATA contains a scalar, the XMLType contains a leaf node with the scalar value. The element name for this node is taken from the optional element string if present, and is "ANYDATA " if it is not. |
STATIC FUNCTION createXML (
|
Creates an XML instance from a BLOB . |
STATIC FUNCTION createXML (
|
Creates an XML instance from a BFILE . |
Parameter | Description |
---|---|
xmlData |
The actual data in the form of a BFILE , BLOB , CLOB , REF cursor, VARCHAR2 or object type. |
schema |
Optional Schema URL to be used to make the input conform to the given schema. Caution: Oracle does not support use of types generated by Schema Registration (see Oracle XML DB Developer's Guide). |
validated |
Flag to indicate that the instance is valid according to the given XML Schema. (Default is 0 ) |
wellformed |
Flag to indicate that the input is well formed. If set, then the database would not do well formed check on the input instance. (Default is 0 ) |
element |
Optional element name in the case of the ADT_1 or REF CURSOR constructors. (Default is NULL ). Caution: Oracle does not support use of types generated by Schema Registration (see Oracle XML DB Developer's Guide). |
csid |
The character set id of input XML data. |
Member function. Checks if the node exists. If the XPath string is NULL
or the document is empty, then a value of 0 is returned, otherwise returns 1. The options are described in the following table.
Syntax | Description |
---|---|
MEMBER FUNCTION existsNode(
|
Given an XPath expression, checks if the XPath applied over the document can return any valid nodes. |
MEMBER FUNCTION existsNode(
|
This member function uses the XPath expression with the namespace information and checks if applying the XPath returns any nodes or not. |
Parameter | Description |
---|---|
xpath |
The XPath expression to test. |
nsmap |
Optional namespace mapping. |
Member function. Extracts an XMLType
fragment and returns an XMLType
instance containing the result node(s). If the XPath does not result in any nodes, then returns NULL
. The options are described in the following table.
Syntax | Description |
---|---|
MEMBER FUNCTION extract(
|
Given an XPath expression, applies the XPath to the document and returns the fragment as an XMLType . |
MEMBER FUNCTION extract(
|
This member function applies the XPath expression and namespace mapping, over the XML data to return a XMLType instance containing the resultant fragment. |
Parameter | Description |
---|---|
xpath |
The XPath expression to apply. |
nsmap |
Optional prefix to namespace mapping information. |
Member function. Returns a BLOB
containing the serialized XML representation; if the BLOB
returned is temporary, it must be freed after use.
MEMBER FUNCTION getBlobVal( csid IN NUMBER) RETURN BLOB DETERMINISTIC;
Parameter | Description |
---|---|
csid |
The desired character set ID of output BLOB |
Member function. Returns a CLOB
containing the serialized XML representation; if the CLOB
returned is temporary, it must be freed after use.
MEMBER FUNCTION getClobVal() RETURN clob deterministic;
Member function. Returns the namespace of the top level element in the instance. Returns NULL
if the input is a fragment or is a non-schema based instance.
MEMBER FUNCTION getNamespace return varchar2 deterministic;
Member function. Returns a numeric value, formatted from the text value pointed to by the XMLType
instance. The XMLType
must point to a valid text node that contains a numerical value. The options are described in the following table.
MEMBER FUNCTION getNumberVal() RETURN number deterministic;
Member function. Gets the root element of the XMLType
instance. Returns NULL
if the instance is a fragment.
MEMBER FUNCTION getRootElement return varchar2 deterministic;
Member function. Returns the XML Schema URL corresponding to the XMLType
instance, if the XMLType
instance is a schema-based document. Otherwise returns NULL
.
MEMBER FUNCTION getSchemaURL return varchar2 deterministic;
Member function. Returns the document as a string. Returns s string containing the seralized XML representation, or in case of text nodes, the text itself. If the XML document is bigger than the maximum size of the VARCHAR2
, which is 4000, then an error is raised at run time.
MEMBER FUNCTION getStringVal() RETURN varchar2 deterministic;
Determines if the XMLType
instance corresponds to a well-formed document, or a fragment. Returns 1 or 0 indicating if the XMLType
instance contains a fragment or a well-formed document.
MEMBER FUNCTION isFragment() RETURN number deterministic;
Member function. Determines whether the XMLType
instance is schema-based or not. Returns 1 or 0 depending on whether the XMLType
instance is schema-based.
MEMBER FUNCTION isSchemaBased return number deterministic;
Member function. Checks if the input instance is conformant to a specified schema. Does not change the validation status of the XML instance. If a XML Schema URL is not specified and the xml document is schema based, the conformance is checked against the XMLType
instance's own schema.
member function isSchemaValid( schurl IN VARCHAR2 := NULL, elem IN VARCHAR2 := NULL) return NUMBER deterministic;
Parameter | IN / OUT | Description |
---|---|---|
schurl |
(IN) |
The URL of the XML Schema against which to check conformance. |
elem |
(IN) |
Element of a specified schema, against which to validate. This is useful when we have a XML Schema which defines more than one top level element, and we want to check conformance against a specific one of these elements. |
Member function. Returns the validation status of the XMLType
instance -- tells if a schema based instance has been actually validated against its schema. Returns 1 if the instance has been validated against the schema, 0 otherwise.
MEMBER FUNCTION isSchemaValidated return NUMBER deterministic;
Member procedure. Validates the XML instance against its schema if it hasn't already been done. For non-schema based documents an error is raised. If validation fails an error is raised; else, the document's status is changed to validated.
MEMBER PROCEDURE schemaValidate( self IF OUT NOCOPY XMLType);
Parameter | IN / OUT | Description |
---|---|---|
self |
(OUT) |
XML instance being validated against the schema. |
Member function. Sets the VALIDATION
state of the input XML instance.
MEMBER PROCEDURE setSchemaValidated( self IF OUT NOCOPY XMLType, flag IN BINARY_INTEGER := 1);
Parameter | IN / OUT | Description |
---|---|---|
self |
(OUT) |
XML instance. |
flag |
(IN) |
0 - NOT VALIDATED ; 1 - VALIDATED (Default) |
Member procedure. Converts the XML value to an object type using the XMLSCHEMA
mapping, if available. If a SCHEMA
is not supplied or the input is a non-schema based XML, the procedure uses cannonical mapping between elements and object type attributes.
MEMBER PROCEDURE toObject( SELF in XMLType, object OUT "<ADT_1>", schema in varchar2 := NULL, element in varchar2 := NULL);
Parameter | IN / OUT | Description |
---|---|---|
SELF |
(IN) |
Instance to be converted. Implicit if used as a member procedure. |
object |
(IN) |
Converted object. An object instance of the required type may be passed in to this function |
schema |
(IN) |
Schema URL. The mapping of the XMLType instance to the converted object instance may be specified using a schema. Caution: Oracle does not support use of types generated by Schema Registration (see Oracle XML DB Developer's Guide). |
element |
(IN) |
Top-level element name. An XML Schema document does not specify the top-level element for a conforming XML instance document without this parameter. Caution: Oracle does not support use of types generated by Schema Registration (see Oracle XML DB Developer's Guide). |
Member function. This member function transforms the XML data using the XSL stylesheet argument and the top-level parameters passed as a string of name=value pairs. If any of the arguments other than the parammap is NULL
, then a NULL
is returned.
MEMBER FUNCTION transform( xsl IN XMLType, parammap in varchar2 := NULL) RETURN XMLType deterministic;
Parameter | IN / OUT | Description |
---|---|---|
xsl |
(IN) |
The XSL stylesheet describing the transformation |
parammap |
(IN) |
Top level parameters to the XSL - string of name=value pairs |
XMLType
constructor. The options are described in the following table.
Syntax | Description |
---|---|
constructor function XMLType(
|
This constructor function creates an optionally schema-based XMLType instance using the specified schema and xml data parameters. |
constructor function XMLType(
|
This constructor function creates an optionally schema-based XMLType instance using the specified schema and xml data parameters. |
constructor function XMLType (
|
This constructor function creates an optionally schema-based XMLType instance from the specified object type parameter. |
constructor function XMLType(
|
This constructor function creates an optionally schema-based XMLType instance from the specified REF CURSOR parameter. |
constructor function XMLType(
|
This constructor function creates an optionally schema-based XMLType instance from the specified ANYDATA parameter.If the ANYDATA instance contains an ADT, the XMLType returned is the same as would be returned for a call directly on the ADT. If the ANYDATA contains a scalar, the XMLType contains a leaf node with the scalar value. The element name for this node is taken from the optional element string if present, and is "ANYDATA " if it is not. |
constructor function XMLType(
|
This constructor function creates an optionally schema-based XMLType instance from the specified BLOB parameter. |
constructor function XMLType(
|
This constructor function creates an optionally schema-based XMLType instance from the specified BFILE parameter. |
Parameter | Description |
---|---|
xmlData |
The data in the form of a BFILE , BLOB , CLOB , REF s, VARCHAR2 or object type. |
schema |
Optional Schema URL to be used to make the input conform to the given schema. Caution: Oracle does not support use of types generated by Schema Registration (see Oracle XML DB Developer's Guide). |
validated |
Indicates that the instance is valid to the given XML Schema. |
wellformed |
Indicates that the input is well formed. If set, then the database would not do well formed check on the input instance. |
element |
Optional element name in the case of the ADT_1 or REF CURSOR constructors. (Default is NULL ). Caution: Oracle does not support use of types generated by Schema Registration (see Oracle XML DB Developer's Guide). |
csid |
The character set id of input XML data. |