xsd2cpp
XmlPlus
main.cpp
The main.cpp aims to demonstrate the multiple options available(parsing/writing/validating xml-files etc.) around the schema and xml files. Further, in this document, in relation to xsd2cpp, the <name> token would signify the name(excluding extension like .xsd) of the supplied XML-Schema. For instance, given a XML-Schema file simpleTypesDemo.xsd, the <name> would mean "simpleTypesDemo" token.
simpleTypesDemo.xsd
$ xsd2cpp Usage: 1. xsd2cpp xsd-file [outdir] outdir: directory to output the generated source to (if unspecified, defaults to xsd-file-name) -s : do not terminate on error 2. xsd2cpp -v prints verion 3. xsd2cpp -h prints help
$ xsd2cpp simpleTypesDemo.xsd . output path: . => Generating source files... => Generating automake/autoconf files ... => Generating README.build.txt file ...
main.cpp.template
$ ./autogen.sh
$ make
$ make install
$ make doxygen-doc
$ xsd2cpp XML-Schema outdir $ cd outdir $ run configure ( with your choice of options) $ make $ make install
--prefix
autogen.sh
configure
build/
The built library alongwith the generated headers for user supplied XML-Schema, can be consumed by user applications in their builds. One example of how to consume the built library/headers, comes alongwith the generated sources viz. main.cpp. The main.cpp includes the generated headers and links to the built library, and makes a binary named <name>run. This <name>run binary demostrates all the use cases around the XML-Schema, that XmlPlus supports. So in that sense main.cpp serves as an example user application, showing how to consume the C++ library built for a XML-Schema file.
$ pwd /Users/goofy/xmlplus/examples/simpleTypesDemo $ find build -type d build/ build/bin/ build/lib/ build/include/ $ find build -type f build/bin/simpleTypesDemorun build/lib/libsimpleTypesDemo.0.dylib build/lib/libsimpleTypesDemo.a build/lib/libsimpleTypesDemo.la
$ ./build/bin/simpleTypesDemorun --help Usage: ./build/bin/simpleTypesDemorun [options] [XMLfile] Options: -s, --sample create a schema-driven sample xml-file -w, --write write a xml-file using populated Document Note: populateDocument() function in main.cpp template, must be used to populate the Document -v, --validate validate input xml-file(against compiled schema) -r, --roundtrip roundtrip (read->write) input xml-file -u, --row perform read->operate->write operations on input xml-file -h, --help print help
chooseDocumentElement(...)
void chooseDocumentElement(NoNS::Document* xsdDoc) { // uncomment one of folowing to choose root xsdDoc->set_root_mails(); //xsdDoc->set_root_header(); //xsdDoc->set_root_Date(); }
<name>run
sample.xml
populateDocument(...)
simpleTypesDemorun
$ ./build/bin/simpleTypesDemorun -v st.xml validating file:st.xml => validation failed Error: { Expected: => Element '{http://www.example.com/STDemo} anIntMax5k' Got: => Element '{http://www.example.com/STDemo} anIntMax10' element: myComplexTypeElem file: st.xml line,column: 43, 2 }
$ ./build/bin/simpleTypesDemorun -v st.xml validating file:st.xml => validated successfully
updateOrConsumeDocument(...)