Skip to content

An XML schema compiler written in C++, which generates C++ code for marshalling and unmarshalling objects

License

Notifications You must be signed in to change notification settings

rajgoel/schematicpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

schematic++

An XML schema compiler for C++, written in C++.

Forked from https://github.com/Tjoppen/james and partly rewritten to produce a simple class structure using c++20 features.

Purpose/goals

The purpose of this program is to transform a subset of XML schema defintions into C++ code for marshalling and unmarshalling documents conforming to one or more schemas. The generated code should not be needlessly complicated (no getters or setters). The number of dependencies should be kept to a minimum.

Dependencies

schematic++ requires Xerces-C++ 3.2.x. On Ubuntu Linux Xerces can be installed by

sudo apt install libxerces-c-dev

Build the program

The program is built like a typical CMake project. A normal build will look something like this (output omitted):

 ~/schematicpp$ mkdir build
 ~/schematicpp$ cd build
 ~/schematicpp/build$ cmake ..
 ~/schematicpp/build$ make

Install the program

After building the program, it can be installed by

~/schematicpp/build$ sudo make install

A short guide to usage

Running the program without arguments produces the following usage information:

schematic++ v[VERSIONNUMBER]

USAGE: schematic++ [-v] [-s] -n <namespace> -o <output-dir> -i <schema_1> ... <schema_n>
 -v	Verbose mode
 -s	Simulate generation but don't write anything to disk
 -n	Provide C++ namespace
 -o	Provide output directory
 -i	Provide list of XML schema definition files

 Generates C++ classes for marshalling and unmarshalling XML to C++ objects according to the given schemas.

The program parses the XML schema definition files in the given order and creates the files <type>.cpp and <type>.h for each type defined. These files can be found in the folder <outputdir>/<namespace>/. All classes generated are derived from a base class XMLObject which can be found in the folder <outputdir>/.

Furthermore, the program generates a file CMakeLists.txt that populates the CMake variables <namespace>_SOURCES and <namespace>_HEADERS. When using CMake, these variables can be set by using the command include(<namespace>/CMakeLists.txt) within a CMakeLists.txt located in your <outputdir> folder.

In your application you have three possibilities to create an XML object:

Create XML object from input stream

Given an input stream, e.g. std::cin, providing the XML you can use

std::unique_ptr<XML::XMLObject> root(XML::XMLObject::createFromStream(std::cin));

Create XML object from input string

Given a string xmlString containing the XML you can use

std::unique_ptr<XML::XMLObject> root(XML::XMLObject::createFromString(xmlString));

Create XML object from input file

Given a string filename naming a file containing the XML you can use

std::unique_ptr<XML::XMLObject> root(XML::XMLObject::createFromFile(filename));

Example

The example directory contains several XSD files and the source code of a rudimentary XML parser that uses the classes generated by schematic++.

You can create the classes corresponding to the provided XML schemas by

# Go to example directory
cd example
# Build classes from XML schemas
../schematic++ -v -n bpmn -o BPMNParser -i DC.xsd DI.xsd BPMNDI.xsd Semantic.xsd BPMN20.xsd

After this step, the files XMLObject.h and XMLObject.cpp should have been copied into the BPMNParser folder. If not, you should copy these manually from the lib folder. The generated classes should have been created in the BPMNParser/bpmn.

Build library only

You can build a library by

cd BPMNParser
mkdir build
cmake ..
make

This creates a single header file lib/BPMNParser.h and a library lib/libBPMNParser.a.

Build library and executable

You can also build an executable using the library by

cd BPMNParser
mkdir build
cmake -DMAIN=main.cpp -DEXE=bpmnParser ..
make

This creates the library and an executable bpmnParser.

Build executable manually

Once the library is built, you can manually create an executable by

cd BPMNParser
g++ -std=c++20 main.cpp XMLObject.cpp bpmn/*.cpp  -L./lib  -lBPMNParser  -lxerces-c -o bpmnParser

Runing the executable

You can run the executable by

cd example
./BPMNParser/bpmnParser diagram.bpmn

About

An XML schema compiler written in C++, which generates C++ code for marshalling and unmarshalling objects

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published