File:  [Public] / xmlschema / algorithm
Revision 1.1: download - view: text, annotated - select for diffs
Mon Dec 3 17:47:09 2001 UTC (22 years, 6 months ago) by richard
Branches: MAIN
CVS tags: HEAD
Algorithm for validating an element

Definitions:

"Abort" means report an error, "assess" the element, and return.

"Assess means ...

Algorithm validateElement:

We start with an element to be validated, a schema, and in the usual
case an element declaration determined when the parent element was
validated.  We may not have a declaration 
 (a) at the start of validation
 (b) if the element matched a wildcard in the parent's content model
 (c) if the parent was invalid
 XXX are these all the cases?

It may also be possible to start validating with a user-supplied type but
no element declaration, but I won't consider that here.

If there is no element declaration, try to find a global declaration
for the element.

XXX is this the right thing to do if the parent was invalid?  What if
there was a local declaration for the element name, but the content
model wasn't satisified?

If we now have an element declaration, get the associated type definition.
XXX what if the type is not defined?

Check the xsi: attributes of the element:
 - complain about unknown ones and set their type to no value
 - validate them against XXX what?  The xsi: schema doesn't have types.

Look at the element declaration to determine whether the element is nullable
XXX what if there is no element declaration?

XXX what is the stuff about "import" here in applyschema.py?

See if the element has an xsi:nil attribute.  If it does:
  If it wasn't nullable, report an error and abort.
  If the xsi:nil attribute is valid and its normalized value is "true",
  note that the element is nulled.  XXX what if it's invalid?

See if it has an xsi:type attribute.  If it does:
  If the xsi:type attribute is valid XXX what is it isn't?
    The type name is the normalized value of the attribute
    Check that the prefix of the type name is bound XXX what if it isn't
    Look for a global type named by the value.
    If there isn't such a type, abort.
    If we already had a type for the element, check that the xsi:type is
    a subtype of it.  If not, abort.
    Set the type to the xsi:type.

If we still don't have a type, we are going to validate the element laxly.

If the element is nulled:
  If the element has children, report an error.
  Otherwise note that it is null.
  XXX what's the TODO about fixed value in validateElementNull?

If we have a type:
  If the type is simple (XXX not the ur-type, either AbInitio or SimpleType):
    If the element is not nulled, validateElementSimple()
    If we have an element declaration, validateKeys()
    Assess and return.
  Otherwise, it's a complex type.
  If the type is abstract, abort.
  Note the type's attribute declarations and prohibited substitutions
Otherwise (no type) set the attribute declarations and prohibited substitutions
  to none.

AssignAttributeTypes()
ValidateAttributeTypes()

If the element is not nulled:
  If we have a type:
    validateContentModel
  validateChildTypes

If we have an element declaration, validateKeys()

Assess and return.


Algorithm validateElementSimple:

Check that the element has no attributes except xsi:*
If it does, report an error and return
Check that it doesn't have any element children
If it does, report and error and return 
XXX what is the TODO about marking as not validated in validateTextModel?
If we have a declaration, and it has a value constraint, and there were
  no text children, set the text to the (normalized) default value.
Otherwise set the text to the text children (possibly empty string).
ValidateText()
If it fails report error and set normalized value to none.
If there's a fixed value constraint, check it.
If it fails, report error and set normalized value to none.

Algorith ValidateText:

If the type is the ur type, return
XXX ... atomic, list, union ...


Webmaster