Generated Reader and Writer Programs

Another capability that is related to -genTest is the capability to generate sample reader and writer programs. These can act as guides or templates in developing more advanced applications.

The -genReader option causes a reader program (reader.c) to be generated. This program will read data from a file containing an XML document and decode the document into a corresponding data structure. The data structure to be used will either be chosen randomly from the provided schema file, or the -usepdu option may be used to select the global element to be used.

The -genWriter option causes a writer program (writer.c) to be generated. The global element to be used as the basis for this program can be selected using -usepud option as was done for the reader above. If -genTest was specified at the same time as -genWriter, a section will be added to the writer to populate a data structure with test data for encoding. If -genTest was not specified, a "TODO" section is added to the writer to allow the user to add their own code to populate a variable of the type to be encoded.

The -genRWTest option causes a read/write program to be generated. This reads in a document of a given XML schema type (as above, this may be specified using -usepdu ), decodes it, and then reencodes iand writes the document back out. This can be useful for doing transformations on a document such as automatically changing the values of certain fields. It is also useful for round-trip testing.

The -zip options can be used in conjunction with -genReader and -genWriter switches to produce programs that will read and write documents in compressed form. Also, -c14n can be used to produce a writer program that will output an XML document in canonical form.