DB2 Version 9.7 for Linux, UNIX, and Windows

FP1: XML schema maxOccurs attribute values greater than 5000 are parsed differently

Starting in Version 9.7 Fix Pack 1, if you specify a value greater than 5000 for the maxOccurs attribute for an element in an XML schema definition, the XML parser treats the value as if you specified "unbounded".

Details

A maxOccurs attribute value of unbounded indicates that the element can appear an unlimited number of times. In that case, starting in Fix Pack 1, an XML document might pass validation when you use the XMLVALIDATE function even if the number of occurrences of an element exceeds the maximum according to the XML schema that you used to validate the document.

User Response

If you use an XML schema that defines an element that has a maxOccurs attribute value that is greater than 5000 and you want to reject XML documents that have a maxOccurs attribute value greater than 5000, you can define a trigger or procedure to check for that condition. In the trigger or procedure, use an XPath expression to count the number of occurrences of the element and return an error if the number of elements exceeds the maxOccurs attribute value

For example, the following trigger ensures that a document never has more than 6500 phone elements:
CREATE TRIGGER CUST_INSERT
  AFTER INSERT ON CUSTOMER
  REFERENCING NEW AS NEWROW
  FOR EACH ROW MODE DB2SQL
BEGIN ATOMIC
  SELECT CASE WHEN X <= 6500 THEN 'OK - Do Nothing'
              ELSE RAISE_ERROR('75000', 'TooManyPhones')  END
  FROM (
    SELECT XMLCAST(XMLQUERY('$INFO/customerinfo/count(phone)') AS INTEGER) AS X
    FROM CUSTOMER
    WHERE CUSTOMER.CID = NEWROW.CID );
END