Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Taking XML Validation to the Next Level: Explore CAM's Expressive Power : Page 3

The generic-sounding Content Assembly Mechanism, or CAM, is an exciting step beyond XML Schema, but it's new and not well documented. This article series represents CAM: The Missing Manual. This last installment is a deep exploration of CAM's ability to express exactly what you need for data-centric documents.




Application Security Testing: An Integral Part of DevOps

CAM Data Characteristics and Types

With XML Schema, data types are treated separately from other data characteristics (facets in XML Schema terminology). Each of them, however, ultimately ends up as an attribute on an <xs:element>. With CAM, data type is just one additional characteristic of an element; all such data characteristics are implemented with predicates embedded in rules.

Table 2 organizes the available data characteristics (datatypes, facets and predicates) in logical groups for ease of comparison.

Table 2. Data Characteristics: This table shows how to map various aspects of data between XML Schema and CAM.
Characteristic XML Schema CAM
Data type <xs:element . . . type="xs:int"> setDatatype(int) or datatype(int)
String value length <xs:minLength value="3">
<xs:maxLength value="8">
Together the min/max values allow a range of lengths.

<xs:length value="30">
Mutually exclusive with the above, specifies an exact length.
setLength(3, 8)
Two values specify a range of lengths.

A single value specifies an exact length.
String value restriction <xs:restriction base="xs:string">
  <xs:enumeration value="dark"/>
  <xs:enumeration value="bittersweet"/>
  <xs:enumeration value="milk"/>
Values are limited to the specific values enumerated.
Values are limited to the specific values enumerated.

restrictValues(dark|bittersweet|milk, dark)
Optional final argument specifies a default if the user does not provide a value.

Numeric value length <xs:totalDigits value="9">
<xs:fractionDigits value="2"/>
Specifies the length of the whole number and fraction portions of a number.
Specifies the number shape in a WYSIWYG fashion. Zeroes indicate digits must be present.

Octothorps indicate leading/trailing zeroes are not required.

Numeric value <xs:minInclusive value="0">
<xs:maxInclusive value="10">
The upper/lower bounds are permissible values.

<xs:minExclusive value="0">
<xs:maxExclusive value="10">
The upper/lower bounds are not permissible values.

Specifies an inclusive range. Exclusive range is not specifically supported but may be achieved with an appropriate inclusive range.
General data shape <xs:pattern value="-?[0-9]+"/>
<xs:pattern value="ITEM.\d{2}"/>
<xs:pattern value="\d{4}-\d{2}-\d{2}T\d\d:\d\d:\d\d"/>
Value is a regular expression.
Value is a custom mask expression.
Whitespace <xs:whitespace value= "preserve"/>
Preserve whitespace as entered.

<xs:whitespace value= "replace"/>
Replace any whitespace with the space character.

<xs:whitespace value= "collapse"/>
Replace then reduce any multiple spaces to a single one.

Not supported.

Author's Note: For further details on the XML Schema side, see Constraining Facets and Regular Expressions in the XML Schema Specification, Part 2. For further details on the CAM side, see Matrix of CAM Predicates and Section 3.4.3: CAM Content Mask Syntax in the CAM Specification. The CAM mask characters are also shown in Part I of this article.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date