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 [-p prefix] [-o outFile] F.rng


-p prefix

If you supply this optional argument, the given prefix will be appended to the front of every generated name.

For example, suppose you use this command:

pyrang -p 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.


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

-o outFile

If this argument is provided, output is written to that file. Any existing file is deleted (assuming you have write permission for that file).

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

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

pyrang -o roster.rng

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

from rnc_roster import *