Well-formed XML only promises matching tags. A claims document that is missing policyNumber is still well-formed—and still useless. DB2 for z/OS can check documents against an XML Schema stored in the XML schema repository (XSR). Validation can be automatic (an XML type modifier on the column) or explicit (DSN_XMLVALIDATE, the z/OS form of what LUW calls XMLVALIDATE). This page covers schemas, the XSR, registration, deletion, versioning, and how validation actually runs.
An XML schema (W3C XML Schema, XSD) describes which elements and attributes are allowed, their types (string, decimal, date), occurrence counts, and namespaces. One “schema” can be several schema documents that import or include each other—for example a common header.xsd plus order.xsd.
Db2 validation asks: given this instance document, does it conform to a registered schema? That is more than well-formedness (XMLPARSE) and different from business rules you write in SQL. Schema types also affect how values are typed inside XQuery after validation.
Schema documents you register must be in the Unicode encoding scheme. Plan your build pipeline so XSDs are UTF-8 before they hit XSR_REGISTER.
The XSR is Db2’s catalog for XML schemas used to validate (and historically to annotate) documents in XML columns. IBM creates it during install or migration. The sample DDL lives in SDSNSAMP (DSNTESR-style members processed by DSNTIJRT).
Objects include database DSNXSR, table spaces such as SYSXSR, and tables including:
The SQL schema name for user-registered XML schemas on z/OS is SYSXSR (or null, which defaults to SYSXSR). That is not your application schema HR or PAYROLL. The name part (for example POSCHEMA) is an SQL identifier; unquoted names fold to uppercase.
Important operational rule: do not drop or recreate XSR objects after you start validating. IBM warns that doing so can cause unexpected behavior. Treat XSR like catalog: back it up with the rest of the subsystem, and change contents through the supplied procedures.
If you never validate, you can skip XSR setup. If you plan DSN_XMLVALIDATE or type modifiers, complete the installation steps for XML schema support (stored procedures, WLM environment, JDBC/SQLJ driver pieces the procedures need).
Registration is a conversation with three (or four) stored procedures, not a CREATE SCHEMA statement. Schema documents are passed as BLOB values.
| Procedure | Role |
|---|---|
| SYSPROC.XSR_REGISTER | Start registration: primary schema document, SQL name, optional location |
| SYSPROC.XSR_ADDSCHEMADOC | Add further XSD documents that belong to the same XML schema |
| SYSPROC.XSR_COMPLETE | Finish registration; schema becomes usable for validation |
| SYSPROC.XSR_REMOVE | Delete a registered XML schema from the XSR |
123456789101112131415161718192021222324252627-- 1. Primary document (rschema must be SYSXSR or null) CALL SYSPROC.XSR_REGISTER( 'SYSXSR', -- rschema 'POSCHEMA', -- name -> SYSXSR.POSCHEMA :schema_location, -- optional schema location URI, or null :xsd_blob, -- primary XSD as BLOB :properties_blob -- optional properties, or null ); -- 2. Additional documents in the same schema (if any) CALL SYSPROC.XSR_ADDSCHEMADOC( 'SYSXSR', 'POSCHEMA', :doc_location, :xsd_blob2, :properties_blob ); -- 3. Complete — for-decomposition must be 0 on z/OS CALL SYSPROC.XSR_COMPLETE( 'SYSXSR', 'POSCHEMA', :properties_blob, 0 ); COMMIT;
XSR_COMPLETE folds undelimited names to uppercase. Pass '"POschema"' if you need mixed case. The for-decomposition argument must be 0: annotated schema decomposition is not supported on z/OS the way LUW supports DECOMPOSE XML DOCUMENT.
Until COMPLETE succeeds, the schema is not ready for validation. A failure in the middle leaves a partial registration—clean up with XSR_REMOVE and retry rather than guessing at catalog rows.
Day-to-day XSR work is procedure calls plus SELECT on the SYSIBM.XSR* tables (with the usual catalog privileges). Administration tasks:
Do not UPDATE XSR tables with ordinary SQL to “fix” a schema. The compiled grammar in the repository must stay consistent with the documents. Always go through the procedures.
SYSPROC.XSR_REMOVE deletes a registered XML schema from the XSR. Call it with the same rschema and name you registered.
12CALL SYSPROC.XSR_REMOVE('SYSXSR', 'POSCHEMA'); COMMIT;
Remove type-modifier references first (ALTER the XML column) if the column still names that schema. Removing a schema that a modifier still lists leaves you with a column definition pointing at a missing XSR object—validation then fails for new writes. Plan the order: ALTER modifier → drain in-flight work → XSR_REMOVE.
Deletion does not rewrite existing XML values. Rows already stored stay as they are. Only future validation calls need the schema to still exist.
XML schema validation is determining whether structure, content, and data types of a document are valid according to a schema. On z/OS you do it in two supported ways:
| Method | When to use | How |
|---|---|---|
| XML type modifier | Column must always contain valid documents | CREATE/ALTER TABLE ... XML(XMLSCHEMA ID SYSXSR.name) |
| DSN_XMLVALIDATE | Optional or statement-level validation; choose schema in SQL | INSERT ... VALUES (DSN_XMLVALIDATE(:xml, 'SYSXSR.NAME')) |
| No validation | Well-formed XML is enough; producers are trusted | Plain XML column; still must parse as well-formed |
DSN_XMLVALIDATE returns an XML value. If validation fails, the statement errors. Forms include:
12345INSERT INTO PURCHASE_ORDER (PO_ID, CONTENT) VALUES ( 1001, DSN_XMLVALIDATE(:xml_hv, 'SYSXSR.POSCHEMA') );
There have been two implementations: an older user-defined SYSFUN.DSN_XMLVALIDATE and the built-in SYSIBM.DSN_XMLVALIDATE. New code should use the built-in. IBM documents a migration path if you still call the UDF.
On LUW you would write XMLVALIDATE(XMLPARSE(...) ACCORDING TO XMLSCHEMA ID ...). Do not paste that into z/OS COBOL unchanged. Conceptually it is the same step: parse or supply XML, validate, store.
An XML type modifier attaches one or more schemas to the column. Every INSERT or UPDATE of that column validates against a schema in the list. You do not have to remember DSN_XMLVALIDATE in every program—which is the point for shops with many writers.
12345678910CREATE TABLE PURCHASE_ORDER ( PO_ID INTEGER NOT NULL, CONTENT XML (XMLSCHEMA ID SYSXSR.POSCHEMA), PRIMARY KEY (PO_ID) ); -- Later: stop automatic validation ALTER TABLE PURCHASE_ORDER ALTER CONTENT SET DATA TYPE XML;
You can identify schemas by ID (SYSXSR.name) or by URI / target namespace so that whatever schemas exist in that namespace at CREATE/ALTER time are associated. Not every schema the modifier might eventually need must already be registered at CREATE, depending on how you specify the modifier—read the URI vs ID rules before assuming a later REGISTER automatically attaches.
If the column has no modifier, validation is optional: store well-formed XML, or call DSN_XMLVALIDATE when a particular document must be checked.
Real documents change. A 2024 order schema adds a new optional element; a 2026 schema makes it required. Db2 does not magically rewrite old XML. You version schemas as separate XSR objects and evolve the type modifier.
123456789101112-- Accept both versions ALTER TABLE PURCHASE_ORDER ALTER CONTENT SET DATA TYPE XML ( XMLSCHEMA ID SYSXSR.PO1, ID SYSXSR.PO2 ); -- After migration, only PO2 ALTER TABLE PURCHASE_ORDER ALTER CONTENT SET DATA TYPE XML (XMLSCHEMA ID SYSXSR.PO2);
Evolution is this operational process—not an in-place ALTER of an XSD already stored in XSR. To “change” a schema, register a new complete schema and switch references. Trying to overwrite XSR rows in place is unsupported.
Optional elements are easier to evolve than required ones. If producers cannot guarantee the new field, keep it optional in PO2 or you will reject old-shaped documents the moment you drop PO1 from the modifier.
ALTER of the type modifier does not re-validate existing rows. A column can contain documents that would fail the new modifier until you rewrite them. Schedule the data migration; do not assume ALTER TABLE is a data-quality tool.
Beginners turn on a type modifier for every XML column and then wonder why a test payload fails. Veterans pick per column:
Validation costs CPU. Huge documents against complex XSDs are not free. Measure. XML indexes and query still work on unvalidated XML; validation is about integrity, not a prerequisite for XMLQUERY.
Well-formed XML is a Lego castle that does not fall apart. A schema is the picture on the box: “this castle must have a gate and four towers.” The XSR is the library shelf where the librarian keeps those box pictures. Register means putting a new picture on the shelf; remove means taking it down. A type modifier is a sign on the toy bin: “only castles that match these pictures allowed.” DSN_XMLVALIDATE is asking the librarian to check one castle against a picture before you put it in a bin that does not have a sign. When the toy company changes the set, you put a new picture on the shelf (version 2) and eventually stop accepting version 1.
1. Where must XML schemas live before Db2 can validate documents against them?
2. How do you force every INSERT into an XML column to be valid?
3. What is DSN_XMLVALIDATE?
4. Which procedure removes a schema from the XSR?
5. How do you support two document versions in one column?