Example of XML schema registration and removal using stored procedures
DB2® provides the SYSPROC.XSR_REGISTER, SYSPROC.XSR_ADDSCHEMADOC, SYSPROC.XSR_COMPLETE, and SYSPROC.XSR_REMOVE stored procedures. These stored procedures let you register and remove XML schemas and their components.
To register an XML schema with a single XML schema document, you call SYSPROC.XSR_REGISTER and SYSPROC.XSR_COMPLETE.
To register an XML schema with several XML schema documents, you call SYSPROC.XSR_REGISTER for the first schema document, call SYSPROC.XSR_ADDSCHEMADOC once for each of the other schema documents, and then call SYSPROC.XSR_COMPLETE.
To remove an XML schema, you call SYSPROC.XSR_REMOVE.
To modify the contents of an XML schema for which you have already called SYSPROC.XSR_COMPLETE, you need to call SYSPROC.XSR_REMOVE and begin the registration process again.
- Registers an XML schema with an XML schema document.
- Adds another XML schema document to the XML schema.
- Completes registration of the XML schema.
- Drops the XML schema.
EXEC SQL BEGIN DECLARE SECTION;
/********************************************************************/
/* Declare variables: */
/* For SYSPROC.XSR_REGISTER parameters: */
/* Parameter name Value */
/* rschema Schema of the XML schema (must be 'SYSXSR')*/
/* name XML schema name */
/* schemaLocation URI for the XML schema */
/* content XML schema document to be registered */
/* docProperties XML schema document information for an */
/* external XML schema registry */
/* For SYSPROC.XSR_ADDSCHEMADOC parameters: */
/* Parameter name Value */
/* rschema Same as for SYSPROC.XSR_REGISTER */
/* name Same as for SYSPROC.XSR_REGISTER */
/* schemaLocation Same as for SYSPROC.XSR_REGISTER */
/* content Same as for SYSPROC.XSR_REGISTER */
/* docProperties Same as for SYSPROC.XSR_REGISTER */
/* For SYSPROC.XSR_COMPLETE parameters: */
/* Parameter name Value */
/* rschema Same as for SYSPROC.XSR_REGISTER */
/* name Same as for SYSPROC.XSR_REGISTER */
/* schemaProperties XML schema information for an external */
/* XML schema registry */
/* issuedForDecomp Indicator: Must be 0 */
/* For SYSPROC.XSR_REMOVE parameters: */
/* Parameter name Value */
/* rschema Same as for SYSPROC.XSR_REGISTER */
/* name Same as for SYSPROC.XSR_REGISTER */
/********************************************************************/
struct {
short len;
char text[128]; } rschema;
struct {
short len;
char text[128]; } name;
struct {
short len;
char text[1000]; } schemaLocation;
SQL TYPE IS BLOB (1M) content;
SQL TYPE IS BLOB (1M) docProperties;
SQL TYPE IS BLOB (1M) schemaProperties;
long issuedForDecomp;
EXEC SQL END DECLARE SECTION;
…
main
{
/********************************************************************/
/* Assign the schema for the XML schema ('SYSXSR') to rschema. */
/********************************************************************/
strcpy(rschema.text,"SYSXSR");
rschema.len=strlen(rschema.text);
/********************************************************************/
/* Assign the XML schema name 'ORDER' to name. */
/********************************************************************/
strcpy(name.text,"ORDER");
name.len=strlen(name.text);
/********************************************************************/
/* Assign the XML schema location 'http://posample.org' to */
/* schemaLocation. */
/********************************************************************/
strcpy(schemaLocation.text,"http://posample.org");
schemaLocation.len=strlen(schemaLocation.text);
…
/********************************************************************/
/* Read the first XML schema document into host variable content */
/* from a file. */
/********************************************************************/
…
/********************************************************************/
/* No information for this XML schema document needs to be stored */
/* for an external registry, so set docProperties to NULL. */
/********************************************************************/
EXEC SQL SET :docProperties = NULL;
/********************************************************************/
/* Call the SYSPROC.XSR_REGISTER to register SYSXSR.ORDER. */
/********************************************************************/
EXEC SQL
CALL SYSPROC.XSR_REGISTER
(:rschema,:name,:schemaLocation,:content,:docProperties);
…
/********************************************************************/
/* Read the second XML schema document into host variable content */
/* from a file. */
/********************************************************************/
…
/********************************************************************/
/* Copy the contents of the second XML schema document into host */
/* host variable docProperties for storage in the XML schema */
/* repository. */
/********************************************************************/
EXEC SQL SET :docProperties = :content;
/********************************************************************/
/* Call the SYSPROC.XSR_ADDSCHEMADOC to register add the second */
/* document to SYSXSR.ORDER. */
/********************************************************************/
EXEC SQL
CALL SYSPROC.XSR_ADDSCHEMADOC
(:rschema,:name,:schemaLocation,:content,:docProperties);
/********************************************************************/
/* No information for this XML schema needs to be stored */
/* for an external registry, so set schemaProperties to NULL. */
/********************************************************************/
EXEC SQL SET :schemaProperties = NULL;
/********************************************************************/
/* Set schemaProperties to NULL because we are not going to store */
/* any schema properties for SYSXSR.ORDER. */
/********************************************************************/
EXEC SQL SET :schemaProperties=NULL;
/********************************************************************/
/* Set issuedForDecomp to 0 because we are not going to use */
/* SYSXSR.ORDER for decomposition. */
/********************************************************************/
issuedForDecomp=0;
/********************************************************************/
/* Call the SYSPROC.XSR_COMPLETE to complete registration of */
/* SYSXSR.CUSTOMER. */
/********************************************************************/
EXEC SQL
CALL SYSPROC.XSR_COMPLETE
(:rschema,:name,:schemaProperties,:issuedForDecomp);
/********************************************************************/
/* Call the SYSPROC.XSR_REMOVE to delete SYSXSR.CUSTOMER from the */
/* XML schema repository. */
/********************************************************************/
EXEC SQL
CALL SYSPROC.XSR_REMOVE
(:rschema,:name);
}