Overview
I had an opportunity to create an XML file conforming to a specific schema, and needed to verify that the XML file matched the schema.
To meet this requirement, I tried the jingtrang library for working with RELAX NG schemas, so here are my notes:
https://pypi.org/project/jingtrang/
I also prepared a Google Colab notebook:
https://colab.research.google.com/github/nakamura196/ndl_ocr/blob/main/jingtrangを試す.ipynb
Trying Validation
Passing Example
Running the following produced no output:
Failing Example
On the other hand, I prepared the following XML file that does not conform to the TEI schema:
The result was as follows. It output that an a element is not allowed and that a TEI or teiCorpus element is expected. This demonstrates that schema conformance checking works:
Summary
I was able to successfully perform validation.
However, since my actual need was to validate against a schema other than TEI/XML, I plan to write a separate article about how to create and configure the RNG file.