summaryrefslogtreecommitdiff
path: root/xsd-examples/cxx/tree/messaging/README
diff options
context:
space:
mode:
Diffstat (limited to 'xsd-examples/cxx/tree/messaging/README')
-rw-r--r--xsd-examples/cxx/tree/messaging/README75
1 files changed, 75 insertions, 0 deletions
diff --git a/xsd-examples/cxx/tree/messaging/README b/xsd-examples/cxx/tree/messaging/README
new file mode 100644
index 0000000..d3d92c6
--- /dev/null
+++ b/xsd-examples/cxx/tree/messaging/README
@@ -0,0 +1,75 @@
+This example shows how to handle XML vocabularies with multiple
+root elements using the element type and element map features
+of the C++/Tree mapping. The main purpose of element types is
+to distinguish object models with the same root type but with
+different root elements. The element map allows uniform parsing
+and serialization of multiple root elements.
+
+The example consists of the following files:
+
+protocol.xsd
+ XML Schema which defines a simple bank account protocol with
+ requests such as withdraw and deposit. Note that some request
+ and response elements are of the same type.
+
+balance.xml
+withdraw.xml
+deposit.xml
+ Sample XML instances for the protocol requests.
+
+protocol.hxx
+protocol.cxx
+ C++ types that represent the given vocabulary.
+
+ These files are generated by the XSD compiler from protocol.xsd using
+ the following command line:
+
+ xsd cxx-tree --root-element-all --generate-element-type \
+ --generate-element-map --generate-serialization protocol.xsd
+
+ Generation of element types instead of parsing and serialization
+ functions is requested with the --generate-element-type option.
+ Generation of the element map is requested with the
+ --generate-element-map option.
+
+dom-parse.hxx
+dom-parse.cxx
+ Definition and implementation of the parse() function that
+ parses an XML document to a DOM document.
+
+dom-serialize.hxx
+dom-serialize.cxx
+ Definition and implementation of the serialize() function that
+ serializes a DOM document to XML.
+
+driver.cxx
+ Driver for the example. It first calls the above-mentioned parse()
+ function to parse the input file to a DOM document. It then calls
+ the parse() function on the element map to parse the root document
+ element to the object model. The object model is returned as a
+ pointer to xml_schema::element_type which is a common base type for
+ all element types. The driver then determines which request it has
+ received either using RTTI or by comparing the root element names.
+ Once the request type is determined, information about it is printed
+ to STDERR and the corresponding response is created. Finally, the
+ driver serializes the opaque response object to a DOM document
+ using the element map and then serializes this DOM document to
+ STDOUT using the above-mentioned serialize() function.
+
+To compile and link the example manually from the command line we can use
+the following commands (replace 'c++' with your C++ compiler name):
+
+c++ -DXSD_CXX11 -c protocol.cxx
+c++ -DXSD_CXX11 -c dom-parse.cxx
+c++ -DXSD_CXX11 -c dom-serialize.cxx
+c++ -DXSD_CXX11 -c driver.cxx
+c++ -o driver driver.o protocol.o dom-parse.o dom-serialize.o -lxerces-c
+
+Note that we need to define the XSD_CXX11 preprocessor macro since the
+source code includes libxsd headers directly.
+
+To run the example on the sample XML request documents execute:
+
+./driver balance.xml
+./driver withdraw.xml
+./driver deposit.xml