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

#p#w#wiggpreventatiglnhihstdtttataptplsisl:o:/n/j//irknaogwXut.MirtgLgaeienitng_hjauilbmluosn使eorgcaotnatrein.tg.ictohmu/bn.aikoa/mtueria/10916./xtmelst2021/main/tei_all.rng

Passing Example

Running the following produced no output:

pyjingtei_all.rng01.xml

Failing Example

On the other hand, I prepared the following XML file that does not conform to the TEI schema:

<a>bbb</a>

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:

p/ycjoinntgentte/in_ga.lxlm.lr:n1g:4n:g.exrmrlor:element"a"notallowedhere;expectedelement"TEI"or"teiCorpus"(withxmlns="http://www.tei-c.org/ns/1.0")

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.