Here we present a script that uses the rnc_validate module
to validate one or more XML files against a given Relax NG
schema.
Command line arguments take this form:
rnck schema file ...
schema
Names a Relax NG schema as either an .rnc file
or an .rng file.
file
Names of one or more XML files to be validated
against .
schema
Here begins the actual rnck script in literate form. First is the usual “pound-bang line” to make the script self-executing under Unix-based systems, followed by an opening comment pointing back at this documentation.
#!/usr/bin/env python #================================================================ # rnck: Validate XML files against an RNC schema. # For documentation, see: # http://www.nmt.edu/tcc/help/pubs/pylxml/ #----------------------------------------------------------------
Next come module imports. We use the Python 3.x style of
print statement. We need the standard
Python sys module for standard I/O streams
and command line arguments.
# - - - - - I m p o r t s from __future__ import print_function import sys
We'll need the lxml.etree module to read
the XML files, but we'll call it et for
short.
import lxml.etree as et
Finally, import the rnc_validate module described in
Section 14, “rnc_validate: A module to validate XML against a
Relax NG schema”.
import rnc_validate