The quickest way to get up and running with your own XML schema file or set of files is to let XBinder generate a sample program for you. This is done using the -genwriter and/or -genreader command-line options. These options cause a complete writer and/or reader program to be generated and, when used in combination with -genmake, cause a makefile to be generated to build the entire project.
For example, suppose you had a schema file named mySchema.xsd that you wanted to generate encoders and decoders for. The following command could be used to generate a complete set of C source files for this schema (note: C++ source files could be generated simply by changing -c to -c++ in this command):
xbinder mySchema.xsd -c -xml -print -genwriter -genreader -genmake
After generation is complete, all that needs to be done is execution of the generated makefile with the make utility program and all of the files will be compiled and linked to form reader and writer executable files. Note that if this is being done on Windows, the -w32 option should be added to generate a makefile that is compatible with the Visual C++ nmake utility.
The generated writer program contains a “TODO” section where code needs to be added to populate a variable of the given data type for encoding. If test code generation (-gentest) is specified, the writer will call a generated test function to automatically populate the test variable.
The generated files can now act as a template on which you can base your own development. The generated mySchemaTest.c (or .cpp) file contains the complete logic necessary to populate a data record corresponding to your schema.
If -gentest was specified without any arguments, the test file contains random data. This code generation can be taken a step further if you have a sample of an XML instance that matches your schema (say, for example, mySchemaInstance.xml). In this case, you can add
-gentest mySchemaInstance.xml
to the command line and test source code will be generated that populates a structure with data from the test instance.
When reader and writer programs are generated, the XSD global element that is used as the basis for the program (i.e. the main variable that is read from or written to) is the first Protocol Data Unit item that is encountered. This may not always be the item you want to use. In this case, the -usepdu command-line option can be used to select the protocl data unit (i.e. global element) you want to use in the generated test code.