Element oriented programming

Michael Kay M.H.Kay at eng.icl.co.uk
Mon Sep 28 17:36:48 BST 1998


>Likewise, it
>must be possible to fire both when the event when the
element is first
>encountered (pre-XXX) and after all of its contents have
been read in are
>available to the event (post-XXX).


In my GedML (genealogy) app, which makes extensive use of
ID/IDREF relationships, I do the semantic validation of an
element in four phases:
1 - when the start element tag is encountered (check that
the context is OK and the attributes are valid)
2 - when the end element tag is encountered (check element
content, and consistency of subelements)
3 - when all elements have been read (check that all
referenced elements exist and are of the right type, and fix
up IDREF pointers)
4 - when all elements have been through stage 3 (check
inter-element consistency, e.g. that the family tree is
non-cyclic.)

So I define four standard events for each element type.

I don't know whether this represents any kind of general
model or whether it is peculiar to my application. I suspect
it applies to any application that handles data structures
that are not purely sequential or hierarchic.

Note: some of the validation I do duplicates that done by a
validating XML processor, but this is such a small part of
the whole that I decided to put it in anyway. E.g. in phase
3 I have to check that the target element is of the right
type, so it's little extra effort to check first that it
exists, even though a validating parser will have done this
already. (Anyway, I can't be sure that the user chose a
validating parser - a SAX limitation?)

I think there's something to be said for separating
"validity checking" events from any other behaviour. The
above discussion all relates to the problem of ensuring that
the XML document conforms to application-defined validity
rules. Of course, it would be much nicer if most of this
could be done declaratively though XSchema extensions.

Mike Kay


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