# - - - - - m a i n
def main():
"""Validate one or more files against an RNC schema.
[ if (command line arguments are valid) ->
if (.rnc and .rng are readable, valid, and up to date) and
(all FILE arguments are valid against that .rng) ->
I
else (if .rnc is readable and valid and .rng can be updated
from the .rnc) and
(all FILE arguments are valid against that .rng) ->
the .rng file := an RNG version of the .rnc
else ->
sys.stderr +:= error message
else ->
sys.stderr +:= error message ]
"""
Processing of the arguments is handled in Section 15.3, “rnck: checkArgs()”. We get back two items: the
path to the schema, and a list of XML file names to be
validated.
#-- 1 --
# [ if sys.argv is a valid command line ->
# schemaPath := the SCHEMA argument
# fileList := list of FILE arguments
# else ->
# sys.stderr +:= error message
# stop execution ]
schemaPath, fileList = checkArgs()
Next we try to build a RelaxValidator
instance from the specified schema.
#-- 2 --
# [ if schemaPath names a readable, valid .rng schema ->
# return a RelaxValidator that validates against that schema
# else if (schemaPath, with .rnc appended if there is no
# extension, names a readable, valid .rnc schema) ->
# if the corresponding .rng schema is readable, valid, and
# newer than the .rnc
# return a RelaxValidator that validates against the
# .rng schema
# else if (we have write access to the corresponding .rng
# schema) and (trang is locally installed) ->
# corresponding .rng schema := trang's translation of
# the .rnc schema into .rng
# return a RelaxValidator that validates against
# translated schema
# else ->
# sys.stderr +:= error message
# stop execution ]
validator = rnc_validate.RelaxValidator ( schemaPath )
For the logic that validates one XML file against our
validator, see Section 15.7, “rnck: validateFile()”.
#-- 3 --
# [ sys.stderr +:= messages about any files from (fileList) that
# are unreadable or not valid against (validator) ]
for fileName in fileList:
validateFile ( validator, fileName )