Skip to content

openSUSE/schvalidator

Repository files navigation

Validate XML Files with ISO Schematron Schemas

License: GPL 3+

Travis CI Code Climate Scrutinizer Code Quality Code Coverage

‟A feather duster to reach the parts other schema languages cannot reach.”

—Rick Jelliffe

The :program:`schvalidator` script validates a given XML file with a ISO Schematron schema. Older Schematron versions are not supported.

Conceptual Overview

XML file and Schematron schema is passed to lxml.isoschematron.Schematron, the result is collected and presented nicely.

Quick Start

To use the program without :command:`pip` and virtual environment, use the following command after cloning this repository:

$ PYTHONPATH=src python3 -m schvalidator -h

Installation

To install :program:`schvalidator`, use the following steps:

  1. Clone this repository:

    $ git clone http://github.com/openSUSE/schvalidator.git
    $ cd schvalidator
    
  2. Create a Python 3 environment and activate it:

    $ python3 -m venv .env
    $ source .env/bin/activate
    
  3. Update the pip and setuptools modules:

    $ pip install -U pip setuptools
    
  4. Install the package:

    $ ./setup.py develop
    

If you need to install it from GitHub directly, use this URL:

git+https://github.com/openSUSE/schvalidator.git@develop

After the installation in your Python virtual environment, the script :program:`schvalidator` is available.

Workflow

The script does the following steps:

  1. Collect all options and arguments through the docopts library.
  2. Check, if a Schematron schema and a XML file is passed to the script and they are available.
  3. If everything is ok, create a Schematron validator with the lxml library and validate the XML file.
  4. Get the result of the validation in an XML report with the root element svrl:schematron-output created by lxml.
  5. Iterate through all svrl:failed-assert elements and output them accordingly. Take into account the role attribute and map them to the logging level.

Done!

Contributing

To contribute to this project, open issues or send us pull requests. Thanks!