Overview

In the following article, I performed XML file validation using jingtrang and RNG files.

Since this jingtrang library can create RNG files from XML files, I decided to try it out.

I also prepared a Google Colab notebook.

https://colab.research.google.com/github/nakamura196/ndl_ocr/blob/main/jingtrangを試す:作成編.ipynb

Creating an RNG File

As the source file for creating the RNG file, I prepared the following:

<root><title>aaa</title></root>

For the above file, execute the following:

pytrangbase.xmlbase.rng

As a result, the following file was created:

<<?g/xr<gmas/rlmt<samae/tmvarl<eamertee/lrar>ml<eetrsneedlm>>isnmaeeo=tetmnn"naet="ntn>"att1xmny>.meap0l=me"n"e=sr="e=o"Nn"otCchtiNot"tadt>lmipeen:""g/>/=/>"rUeTlFa-x8n"g?.>org/ns/structure/1.0"datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">

I tested against this RNG file as follows.

OK: Different text content

<root><title>bbb</title></root>
pyjingbase.rngex1.xml

NG: Missing title

<root><aaa>bbb</aaa></root>
p//yccjooinnnttgeennbtta//seeexx.22r..nxxgmmlle::x112::.12x28m::leerrrroorr::eelleemmeenntt""araoao"t"noitncaolmlpolweetde;anmyiwshseirneg;reexqpueicrteeddeelleemmeenntt""ttiittllee""

NG: Has attributes

<root><titlelang="en">aaa</title></root>
p/ycjoinntgenbta/seex.3r.nxgmle:x13:.2x4m:lerror:foundattribute"lang",butnoattributesallowedhere

Summary

As shown above, it was possible to create an RNG file from a given XML file. While further study is needed on how to write RNG files, having a mechanism to experiment with concrete examples like these is valuable.

We hope this serves as a useful reference for learning about RNG files.