Purchase Order Example
The following example is taken from http://www.w3.org/TR/xmlschema-1/
The CAM template consists of the structure layout expressed as well-formed XML, plus the contextual rules that control the content model. Notice how the data content model is controlled using %% that indicates where data content occurs. The text shown between the %% then acts as a content guide. CAM assumes all items by default are mandatory and you can then modify that using context rules - (see below)
Example CAM template structure definition
<?xml version='1.0'?> <as:CAM CAMlevel="1" version="1.0" xmlns:as="http://www.oasis-open.org/committees/cam" > <as:Header> <as:Description>Sample CAM template for W3C Purchase Order</as:Description> <as:Owner>CAM Example</as:Owner> <as:Version>0.1</as:Version> <as:DateTime>2007-03-06T09:48:00</as:DateTime> <as:Parameters> <as:Parameter name="QuickBooks" values="'true'|'false'" default="false" use="local"/> </as:Parameters> </as:Header> <as:AssemblyStructure> <as:Structure ID="W3C-PO" taxonomy="XML" reference=""> <PurchaseOrder orderDate="%1999-05-20%"> <shipTo type="%US%"> <name>%Alice Smith%</name> <street>%123 Maple Street%</street> <city>%Mill Valley%</city> <state>%CA%</state> <zip>%90952%</zip> </shipTo> <shipDate>%1999-05-25%</shipDate> <comment>%Get these things to me in a hurry, my lawn is going wild!%</comment> <Items> <Item pno="%333-333%"> <productName>%Lawnmower, model BUZZ-1%</productName> <quantity>%1%</quantity> <price>%148.95%</price> <comment>%Please confirm this is the electric model%</comment> </Item> </Items> </PurchaseOrder> </as:Structure> </as:AssemblyStructure> </as:CAM>The structure definition above essentially achieves the same as the schematron example rules do. Next you will see how to add additional usage rules and contextual business rules. These example business use context CAM rules are:
<as:BusinessUseContext> <as:Rules> <as:default> <as:context> <as:constraint action="makeRepeatable(//Items/Item)"/> <as:constraint action="makeOptional(//Item/comment)"/> <as:constraint action="setLength(//shipTo/state,2)"/> <as:constraint action="setDateMask(//PurchaseOrder/shipDate,YYYY-MM-DD)"/> <as:constraint action="makeOptional(//PurchaseOrder/comment)"/> <as:constraint action="restrictValues(//shipTo/@type,'US'| 'CA'| 'MX', 'US')"/> <as:constraint action="setDateMask(//PurchaseOrder/@orderDate,YYYY-MM-DD)"/> <as:constraint action="setNumberMask(//Item/@pno,###-###)"/> <as:constraint action="setNumberMask(//Item/quantity,###)"/> <as:constraint action="setNumberMask(//Item/price,####.##)"/> <as:constraint condition="//Item/@pno = 123-678" action="restrictValues(//shipTo/state,'WA')"> <as:annotation> <as:documentation type="documentation"> Can only ship item 123-678 to Washington State </as:documentation> </as:annotation> </as:constraint> <as:constraint condition="$QuickBooks = true" action="excludeElement(//Item/comment)" /> </as:context> </as:default> </as:Rules> </as:BusinessUseContext>These rules not only indicate the structure use pattern (repeatable, optional items) but also content model for the data - such as /Item/price. Then a context based cross-field conditional constraint is shown - (where a particular item is only available for delivery in WA state).
Additionally a contextual parameter rule is used (declared in <Header>) that modifies the structure (can be based on a parameter value or XPath value). In this case the <comment> element is removed if the PO is intended for use with "QuickBooks" accounting package.
A pretty-printed HTML business rules summary report version can be found here.
The complete CAM template can be viewed here here.
This contrasts with the schematron approach where you must create rules individually for each aspect of the structure usage.
In addition there is now an interactive documentation (iDoc) format available here. The iDoc format is wiki compatible and so can be used to post online registry documentation.
Copyright 2007 David RR Webber and usage license - Creative Commons license
Terms: Attribution-NoDerivs (http://creativecommons.org/licenses/by-nd/2.5/)