When Element objects are created, lxml.objectify must determine which implementation class to use for them.

Data Elements represent the data containers at the leafs.

You can explicitly create tree Elements with the factory.

The algorithm is as follows: Care must be taken if different namespace prefixes have been used for the same namespace.

Namespace information gets merged to avoid duplicate definitions when adding a new sub-element to a tree, but this mechanism does not adapt the prefixes of attribute values: The Py Type constructor takes a string type name, an (optional) callable type check and the custom data class.

As I mentioned before, information is passed to the validation function in the event object, and in the code we see that the member ‘value’ is used to communicate the current value of the field.

The member ‘rc’ (or return code) is used to communicate back if the validation was successful or not.

In that case, the previous value of the field is restored, and the user has to enter the data again.

This is not always desired (for more complicated data, it will probably be much easier to take a look, correct that one typo and continue with the rest of the form), so my preference is actually to mark the field so that the user knows which field needs to be corrected, and have the validation script not report a validation error back to the field: Using this method has implications on the form submission process: The form no longer can verify that the data is correct, so the submission function needs to do another round of validation to see if any of the required fields are not correct (one way to do that is to test all relevant fields to see if the text color is using the error color, or we can use global variables to store the validation state).

For numeric fields, there is a convenient way to validate a value range, but we want to select to run a custom validation script.