Forked from https://github.com/Tjoppen/james and partly rewritten to produce a simple class structure using c++20 features.
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.
schematic++ requires Xerces-C++ 3.2.x. On Ubuntu Linux Xerces can be installed by
sudo apt install libxerces-c-dev
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
After building the program, it can be installed by
~/schematicpp/build$ sudo make install
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:
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));
Given a string xmlString
containing the XML you can use
std::unique_ptr<XML::XMLObject> root(XML::XMLObject::createFromString(xmlString));
Given a string filename
naming a file containing the XML you can use
std::unique_ptr<XML::XMLObject> root(XML::XMLObject::createFromFile(filename));
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
.
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
.
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
.
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
You can run the executable by
cd example
./BPMNParser/bpmnParser diagram.bpmn