Background:XMetaL Author provides APIs that allow you to add your own "business logic validation" for two special cases: the "simple content" of elements (PCDATA) and attribute values. The Journalist demo includes an example of this but requires a little bit of digging to find and set up (we don't ship an invalid file for testing it).
The example included here basically duplicates the Journalist demo script but just deals with this one feature. It also includes an example of an "invalid" file (technically valid according to the DTD but "invalid" according to the "business logic validation" in the MCR file) that will trigger the logic in the script.
Suggested Audience:XMetaL Author developers interested in adding additional checks on XML content that:
- cannot be defined in a DTD, or...
- are not defined in an XSD (even though it might be possible to do so you might not wish to alter an existing Schema), or...
- are not caught properly by XMetaL's XML validation (for whatever reason).
Usage:1) Unzip attached file to an empty folder on your machine (includes DTD, CSS, CTM, MCR and XML).
2) Open the file testDocument.xml in XMetaL Author and see what happens.
3) Examine the script called
On_Check_Element_SimpleContent in the MCR file and adapt it for the needs of your own customization. Note that full validation is forced at document open by including an additional event macro. This is optional of course, as F9 and a standard Save or Save As will still trigger validation.
Notes:It is also possible to "validate" attribute values in a similar way using the event
On_Check_Attribute_Value. See the XMetaL Developer Programmer's Guide. The logic in a script for checking attributes would be virtually identical with the exception that you might also use the
Application.CheckData.AttributeName property.
Please also heed the warning in the Programmer's Guide:
Do not change the DOMNode during the execution of either of these event macros. Unrecoverable errors may result.
If you wish to automatically "correct" these types of issues within a document there are various other events that are more suitable, such as
On_Before_Document_Save or
On_Before_Document_Validate, or in the case of attribute values set using the Attribute Inspector you might wish to do so right after the user has set the value using
On_Before_Set_Attribute_From_AI or
On_After_Set_Attribute_From_AI.