Next / Previous / Contents / TCC Help System / NM Tech homepage

2. Operation of pyrang

This script operates on a Relax NG schema in the XML format. It produces a file containing Python declarations corresponding to the element and attribute names from the schema.

If the schema is expressed in Relax NG Compact Syntax (RNC), the trang utility can translate it. Typically, RNC files have names ending in .rnc, while Relax NG files in the XML format have names ending in .rng. To translate, use this command:

trang F.rnc F.rng

where F is the unqualified name of the file. For example, if your RNC schema is named roster.rnc, translate it using:

trang roster.rnc roster.rng

Once you have the schema in .rng format, here is the general form of the command that executes pyrang:

pyrang [--prefix prefix] [--out outFile] F.rng


--prefix P

If you supply this optional argument, the given P will be appended to the front of every generated name. This option may be abbreviated as “-p”.

For example, suppose you use this command:

pyrang --prefix RNC_ foo.rng

The manifest constant generated for an element named player would be RNC_PLAYER_N instead of the default PLAYER_N.

This option is helpful if your application works with multiple schemas that may have some overlap in their element or attribute names.

--out outFile

If this argument is provided, output is written to the named file. Any existing file is deleted (assuming you have write permission for that file). This option may be abbreviated as “-o”.

If omitted, output is written to the standard output stream.


The name of the input schema file is required; it will generally end in .rng.

Here is an example. This command would read schema file roster.rng and write the corresponding Python definitions to file

pyrang --out roster.rng

You can then include the generated manifest constants in your program using this Python import:

from rnc_roster import *