Next / Previous / Contents / TCC Help System / NM Tech homepage

16. rnck: A standalone script to validate XML against a Relax NG schema

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 ...

Names a Relax NG schema as either an .rnc file or an .rng file.


Names of one or more XML files to be validated against schema.

16.1. rnck: Prologue

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:

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 15, “rnc_validate: A module to validate XML against a Relax NG schema”.

import rnc_validate