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

15. rnc_validate: A module to validate XML against a Relax NG schema

Here we present a Python module to validate XML files against a Relax NG schema using the techniques described in Section 12, “Automated validation of input files”.

15.1. Design of the rnc_validate module

This module will work from a schema file in either Relax NG Compact Form (.rnc) or XML syntax (.rng).

However, because lxml's validation machinery cannot read .rnc files directly, our module must take its input from an .rng file.

If the schema file name ends in .rnc, we make these assumptions:

  • If there is an .rng file with the same basename as the .rnc, and provided that it is up-to-date (with a newer file modification timestamp), we will use the .rng version.

  • If there is no corresponding .rng version, or if the .rng file is out of date, we assume that the trang utility is locally installed. This utility can translate from .rnc to .rng format.

    We also assume that we have write access so that we can create or recreate the .rng file.