Pre- and Post-conditions (was RE: XSchema: multiple proposals)

Rick Jelliffe ricko at allette.com.au
Wed Jun 3 17:10:03 BST 1998


> From:  Don Park

> >All of which leads me to wonder if is there an (as yet
> >undiscovered) way to
> >represent XML content models in XML without using the basic structure:
>
> Frankly, I would like to see separate definitions for each element,
> attributes, and containment rules.

On approach would be to get rid of the notion of content models entirely
(i.e. leave them where they are in the markup declarations), and replace
them with more generalized pre- and post-conditions. A document is valid if
each post-condition is true at a start-tag and if each pre-condition is true
at the corresponding end-tag.

Following is a really simple version. The reason why this might be useful is
that it allows all sorts of containment constraints to be expressed but in a
decentralized, incremental manner.

---------------------------------------------------------------------------
<!-- XASSERT.DTD -->
<!-- A simple DTD for a schema language using pre- and post-conditions -->
<?xml:namespace ns="XASSERT" ?>

<!NOTATION XASSERT SYSTEM >
<!-- The XASSERT notation is a simple language with the following
     syntax:
 assertion     ::=  simple-test | compound-test
 compound-test ::=  "(" assertion ( "&&" | "||" | "!&" | "!|" ) assertion
")"
 assertion     ::=  Xptr ("==" | "!=" ) ( strings | "#SPECIFIED" )
 strings       ::=  string ( "||" string )*
-->

<!ELEMENT XASSERT:true  ( XASSERT:pre-condition*, XASSERT:post-condition* )>
<!ATTLIST XASSERT:true
      subject ( element | entity | PI | comment | attribute )  "element"
	name ID #REQUIRED >

<!ELEMENT XASSERT:pre-condition  ( #PCDATA )>
<!ATTLIST XASSERT:pre-condition
	id ID #IMPLIED
	notation NOTATION ( "XASSERT" ) "XASSERT" >

<!ELEMENT XASSERT:post-condition  ( #PCDATA )>
<!ATTLIST XASSERT:post-condition
	id ID #IMPLIED
	notation NOTATION ( "XASSERT" ) "XASSERT" >
----------------------------------------------------------------------------

E.g. the following content model
	<!ELEMENT x ( z )>
could be expressed (the XLink is incorrect...dont flame me!!!!!!!!!!)

<XASSERT:true name="z">
	<XASSERT:pre-condition>HERE(parent) == "x" </XASSERT:pre-condition>
</XASSERT:true>

This kind of thing can better express complicated validations, such as that
if a certain element above has an attribute with a certain value, the
current element or its children should not provide some attribute value.

Presumably the syntax should follow ECMA or Perl (Yuck) more, and allow
cascading assertions.

Rick Jelliffe

==========================================================
The XML & SGML Cookbook, by Rick Jelliffe
Charles F. Goldfarb Series on Open Information Management
656 pages + CD-ROM, Prentice Hall 1998, ISBN 0-13-614233-0
http://www.sil.org/sgml/jelliffeXMLAnn.html
http://www.phptr.com/  > Book Search > "Jelliffe"
http://www.amazon.com/exec/obidos/ASIN/0136142230/002-4102466-3352420


xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev at ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/
To (un)subscribe, mailto:majordomo at ic.ac.uk the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo at ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa at ic.ac.uk)




More information about the Xml-dev mailing list