Skip to main content

jingtrang (compact and XML) RELAX NG schema validator and transformer

jingtrang is wrapper of Java based command line tools for working with RELAX NG schemas.

Motivation

RELAX NG and especially compact form of describing XML structures is very efficient.

Unfortunately, with Python, support is rather limited:

  • lxml allows validation of XML based schemas only
  • lxml is based on libxml2 library, which has some minor limitations with regards to RELAX NG validation (in some cases you find error messages like "TODO").
  • package rnc2rng is promising conversion from XML to compact form, but is not really usable (it simply does not work).

In general, it is even not very easy finding command line validator for compact RELAX NG syntax.

RNV is very promising, but version on Sourceforge is rather old and version on GitHub does not have up todate installation instructions.

Other RELAX NG related tools mostly ignore compact syntax.

The only exception to this is jingtrang project hosted on googlecode.

Problem with this tool is, that it takes few steps more then is really convenient to have it easily installed for daily use from console.

As our team is working on Linux as well as on MS Windows, I was looking for cross platform command line solution.

As jingtrang commands (jing and trang) seem to be functioning very well, I have decided to write this jing and trang wrapper.

Delivering (py)jing and (py)trang command line tool

Original command line tools are named jing (validator) and trang (transforming schemas).

To prevent naming conflict, prefix py is used.

Command line interface is exactly the same, as if using it with java interpreter, only introductory java -jar <jarfile.jar> part is not necessary to call.

Here are described only most popular use cases, for more options, consult original jingtrang documentation (download from googlecode or elsewhere and see included html doc).

Installation

Prerequisites are:

  • Python 3.11 or higher
  • Java
  • pip

Install it by:

$ pip install jingtrang

After that, two new scripts are installed:

  • pyjing - RELAX NG validator
  • pytrang - utility for transforming between XML/compact syntax/XSD/few more formats

Note: There is no need to install jing.jar and trang.jar files as they are already included in jingtrang Python package, together with the supporting libraries they need (isorelax.jar, saxon9.jar).

Note: The -C <catalog> option is not available, as it requires resolver.jar (Apache XML Commons Resolver), which upstream does not ship.

pyjing - RELAX NG validator (XML as well as compact syntax)

pyjing serves for validating XML documents against XML as well as compact syntax RELAX NG schemas:

$ pyjing
Jing version 20241231
usage: java com.thaiopensource.relaxng.util.Driver [-i] [-c] [-s] [-t] [-C catalogFile] [-e encoding] RNGFile XMLFile...
RELAX NG is a schema language for XML
See http://relaxng.org/ for more information.

To validate XML using XML syntax RELAX NG schema:

$ pyjing schema.rng file.xml

To validate using compact syntax schema, use -c switch:

$ pyjing -c schema.rnc file.xml

Validation of multiple XML files at once is possible:

$ pyjing schema.rnc samples/*.xml

pytrang - Schema format convertor

pytrang is "schema language translator" supporting not only RELAX NG XML and compact syntax, but also DTD, XSD. It even allows generating initial schema based on sample XML document.

Try to run it:

$ pytrang
fatal: at least two arguments are required
Trang version 20241231
usage: java com.thaiopensource.relaxng.translate.Driver [-C catalogFileOrUri] [-I rng|rnc|dtd|xml] [-O rng|rnc|dtd|xsd] [-i input-param] [-o output-param] inputFileOrUri ... outputFile

pytrang is able auto-detect format from file extension, so you can mostly directly convert without specifying explicitly, what input and output formats are to be used.

Converting compact syntax to XML one can be done by:

$ pytrang root.rnc root.rng

Note: If you use include in your schema, all included schemas will be converted too.

To generate initial RELAX NG schema in compact format from sample XML file, try:

$ pytrang sample.xml initial.rnc

Development

The repository is managed with mise and uv. mise install provisions Python, uv and a JDK; everything else runs through tasks:

$ mise tasks          # list everything available
$ mise run sync       # create .venv with project + dev dependencies
$ mise run test       # run the test suite
$ mise run test-matrix  # run it against Python 3.11 - 3.14
$ mise run lint       # ruff check + format check
$ mise run build      # build sdist and wheel into dist/
$ mise run smoke      # install the built wheel in a throwaway venv, run both CLIs

Releasing:

$ mise run release-check   # lint + matrix tests + smoke test of the built wheel
$ mise run publish         # upload dist/* to PyPI

publish needs a PyPI API token in UV_PUBLISH_TOKEN. Copy mise.local.toml.example to mise.local.toml (gitignored) and put the token there.

Metadata

Release files for jingtrang 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jingtrang 0.3.0
File Size Uploaded Provenance Actions
jingtrang-0.3.0.tar.gz 6.7 MB Without provenance Details for jingtrang-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for jingtrang 0.3.0
File Interpreter ABI Platform Actions
jingtrang-0.3.0-py3-none-any.whl Python 3 none any Details for jingtrang-0.3.0-py3-none-any.whl

Total release size: 13.3 MB

Release files / jingtrang-0.3.0.tar.gz

Download URL jingtrang-0.3.0.tar.gz
Size 6.7 MB
Tags Source
SHA-256 checksum
How to use checksums
504590c0e2cc1b582ab5aea50af3b1f6e9961320f637fc866f2794b7eaba3036
BLAKE2b-256 checksum
How to use checksums
2036a8a04772b99e12a46a09a2430bffc78711b186fe8ae5f000f55cdb107480
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / jingtrang-0.3.0-py3-none-any.whl

Download URL jingtrang-0.3.0-py3-none-any.whl
Size 6.6 MB
Tags Python 3
SHA-256 checksum
How to use checksums
d5eb69d1461fd6539dd275d5caac6e144cf164d890de7a0e990e58673c6fb2ee
BLAKE2b-256 checksum
How to use checksums
80a5aec99ab52daa38c89eccfe39fcf980c584c6fbd7de84bce50d30cc1ebe49
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for jingtrang 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page