Forked from https://github.com/Tjoppen/james and partly rewritten to produce a simple class structure using c++23 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.
A C++23 compiler, CMake 3.26.4 or later, and git.
Xerces-C++ 3.2.x is fetched automatically unless installed already.
To build schematic++, run
mkdir build
cd build
cmake ..
make -j$(nproc)This creates the executable schematic++ in the project folder.
The build type defaults to Release.
After building, run
sudo make installto install schematic++ into /usr/local, or
cmake --install <build> --prefix <target>to copy
bin/schematic++
share/cmake/schematicpp/
to the <target> folder.
A CMake project can then use the program with
find_package(schematicpp REQUIRED)
add_custom_command(... COMMAND schematicpp::schematic++ -n <namespace> -o <dir> -i <schema> ...)Nothing further is needed when schematic++ was installed into /usr/local. For any other folder, add
cmake .. -DCMAKE_PREFIX_PATH=<target>.
Remove the installed files, where <target> is /usr/local or the folder given when installing.
rm <target>/bin/schematic++
rm -rf <target>/share/cmake/schematicppRunning 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.xsdAfter 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
cd build
cmake ..
makeThis 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
cd build
cmake -DMAIN=main.cpp -DEXE=bpmnParser ..
makeThis creates the library and an executable bpmnParser.
Once the library is built, you can manually create an executable by
cd BPMNParser
g++ -std=c++23 main.cpp XMLObject.cpp bpmn/*.cpp -L./lib -lBPMNParser -lxerces-c -o bpmnParserYou can run the executable by
cd example
./BPMNParser/bpmnParser diagram.bpmn