summaryrefslogtreecommitdiff
path: root/examples/cxx/tree/messaging
diff options
context:
space:
mode:
Diffstat (limited to 'examples/cxx/tree/messaging')
-rw-r--r--examples/cxx/tree/messaging/README58
-rw-r--r--examples/cxx/tree/messaging/balance.xml17
-rw-r--r--examples/cxx/tree/messaging/deposit.xml18
-rw-r--r--examples/cxx/tree/messaging/dom-parse.cxx118
-rw-r--r--examples/cxx/tree/messaging/dom-parse.hxx23
-rw-r--r--examples/cxx/tree/messaging/dom-serialize.cxx89
-rw-r--r--examples/cxx/tree/messaging/dom-serialize.hxx21
-rw-r--r--examples/cxx/tree/messaging/driver.cxx145
-rw-r--r--examples/cxx/tree/messaging/makefile72
-rw-r--r--examples/cxx/tree/messaging/protocol.xsd54
-rw-r--r--examples/cxx/tree/messaging/withdraw.xml18
11 files changed, 633 insertions, 0 deletions
diff --git a/examples/cxx/tree/messaging/README b/examples/cxx/tree/messaging/README
new file mode 100644
index 0000000..435a4cf
--- /dev/null
+++ b/examples/cxx/tree/messaging/README
@@ -0,0 +1,58 @@
+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 are
+ generated by the XSD compiler from 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 run the example on the sample XML request documents simply
+execute:
+
+$ ./driver balance.xml
+$ ./driver withdraw.xml
+$ ./driver deposit.xml
diff --git a/examples/cxx/tree/messaging/balance.xml b/examples/cxx/tree/messaging/balance.xml
new file mode 100644
index 0000000..57eeaed
--- /dev/null
+++ b/examples/cxx/tree/messaging/balance.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0"?>
+
+<!--
+
+file : examples/cxx/tree/messaging/balance.xml
+author : Boris Kolpackov <boris@codesynthesis.com>
+copyright : not copyrighted - public domain
+
+-->
+
+<p:balance xmlns:p="http://www.codesynthesis.com/protocol"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.codesynthesis.com/protocol protocol.xsd">
+
+ <account>123456789</account>
+
+</p:balance>
diff --git a/examples/cxx/tree/messaging/deposit.xml b/examples/cxx/tree/messaging/deposit.xml
new file mode 100644
index 0000000..9da3c59
--- /dev/null
+++ b/examples/cxx/tree/messaging/deposit.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0"?>
+
+<!--
+
+file : examples/cxx/tree/messaging/deposit.xml
+author : Boris Kolpackov <boris@codesynthesis.com>
+copyright : not copyrighted - public domain
+
+-->
+
+<p:deposit xmlns:p="http://www.codesynthesis.com/protocol"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.codesynthesis.com/protocol protocol.xsd">
+
+ <account>123456789</account>
+ <amount>1000000</amount>
+
+</p:deposit>
diff --git a/examples/cxx/tree/messaging/dom-parse.cxx b/examples/cxx/tree/messaging/dom-parse.cxx
new file mode 100644
index 0000000..d6ce204
--- /dev/null
+++ b/examples/cxx/tree/messaging/dom-parse.cxx
@@ -0,0 +1,118 @@
+// file : examples/cxx/tree/messaging/dom-parse.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : not copyrighted - public domain
+
+#include "dom-parse.hxx"
+
+#include <istream>
+
+#include <xercesc/dom/DOM.hpp>
+#include <xercesc/util/XMLUniDefs.hpp> // chLatin_*
+#include <xercesc/framework/Wrapper4InputSource.hpp>
+
+#include <xsd/cxx/xml/sax/std-input-source.hxx>
+#include <xsd/cxx/xml/dom/bits/error-handler-proxy.hxx>
+
+#include <xsd/cxx/tree/exceptions.hxx>
+#include <xsd/cxx/tree/error-handler.hxx>
+
+using namespace xercesc;
+namespace xml = xsd::cxx::xml;
+namespace tree = xsd::cxx::tree;
+
+xml::dom::auto_ptr<DOMDocument>
+parse (std::istream& is, const std::string& id, bool validate)
+{
+ const XMLCh ls_id [] = {chLatin_L, chLatin_S, chNull};
+
+ // Get an implementation of the Load-Store (LS) interface.
+ //
+ DOMImplementation* impl (
+ DOMImplementationRegistry::getDOMImplementation (ls_id));
+
+#if _XERCES_VERSION >= 30000
+
+ // Xerces-C++ 3.0.0 and later.
+ //
+ xml::dom::auto_ptr<DOMLSParser> parser (
+ impl->createLSParser (DOMImplementationLS::MODE_SYNCHRONOUS, 0));
+
+ DOMConfiguration* conf (parser->getDomConfig ());
+
+ // Discard comment nodes in the document.
+ //
+ conf->setParameter (XMLUni::fgDOMComments, false);
+
+ // Enable datatype normalization.
+ //
+ conf->setParameter (XMLUni::fgDOMDatatypeNormalization, true);
+
+ // Do not create EntityReference nodes in the DOM tree. No
+ // EntityReference nodes will be created, only the nodes
+ // corresponding to their fully expanded substitution text
+ // will be created.
+ //
+ conf->setParameter (XMLUni::fgDOMEntities, false);
+
+ // Perform namespace processing.
+ //
+ conf->setParameter (XMLUni::fgDOMNamespaces, true);
+
+ // Do not include ignorable whitespace in the DOM tree.
+ //
+ conf->setParameter (XMLUni::fgDOMElementContentWhitespace, false);
+
+ // Enable/Disable validation.
+ //
+ conf->setParameter (XMLUni::fgDOMValidate, validate);
+ conf->setParameter (XMLUni::fgXercesSchema, validate);
+ conf->setParameter (XMLUni::fgXercesSchemaFullChecking, false);
+
+ // We will release the DOM document ourselves.
+ //
+ conf->setParameter (XMLUni::fgXercesUserAdoptsDOMDocument, true);
+
+ // Set error handler.
+ //
+ tree::error_handler<char> eh;
+ xml::dom::bits::error_handler_proxy<char> ehp (eh);
+ conf->setParameter (XMLUni::fgDOMErrorHandler, &ehp);
+
+#else // _XERCES_VERSION >= 30000
+
+ // Same as above but for Xerces-C++ 2 series.
+ //
+ xml::dom::auto_ptr<DOMBuilder> parser (
+ impl->createDOMBuilder (DOMImplementationLS::MODE_SYNCHRONOUS, 0));
+
+ parser->setFeature (XMLUni::fgDOMComments, false);
+ parser->setFeature (XMLUni::fgDOMDatatypeNormalization, true);
+ parser->setFeature (XMLUni::fgDOMEntities, false);
+ parser->setFeature (XMLUni::fgDOMNamespaces, true);
+ parser->setFeature (XMLUni::fgDOMWhitespaceInElementContent, false);
+ parser->setFeature (XMLUni::fgDOMValidation, validate);
+ parser->setFeature (XMLUni::fgXercesSchema, validate);
+ parser->setFeature (XMLUni::fgXercesSchemaFullChecking, false);
+ parser->setFeature (XMLUni::fgXercesUserAdoptsDOMDocument, true);
+
+ tree::error_handler<char> eh;
+ xml::dom::bits::error_handler_proxy<char> ehp (eh);
+ parser->setErrorHandler (&ehp);
+
+#endif // _XERCES_VERSION >= 30000
+
+ // Prepare input stream.
+ //
+ xml::sax::std_input_source isrc (is, id);
+ Wrapper4InputSource wrap (&isrc, false);
+
+#if _XERCES_VERSION >= 30000
+ xml::dom::auto_ptr<DOMDocument> doc (parser->parse (&wrap));
+#else
+ xml::dom::auto_ptr<DOMDocument> doc (parser->parse (wrap));
+#endif
+
+ eh.throw_if_failed<tree::parsing<char> > ();
+
+ return doc;
+}
diff --git a/examples/cxx/tree/messaging/dom-parse.hxx b/examples/cxx/tree/messaging/dom-parse.hxx
new file mode 100644
index 0000000..640b28a
--- /dev/null
+++ b/examples/cxx/tree/messaging/dom-parse.hxx
@@ -0,0 +1,23 @@
+// file : examples/cxx/tree/messaging/dom-parse.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : not copyrighted - public domain
+
+#ifndef DOM_PARSE
+#define DOM_PARSE
+
+#include <string>
+#include <iosfwd>
+
+#include <xercesc/dom/DOMDocument.hpp>
+#include <xsd/cxx/xml/dom/auto-ptr.hxx>
+
+// Parse an XML document from the standard input stream with an
+// optional resource id. Resource id is used in diagnostics as
+// well as to locate schemas referenced from inside the document.
+//
+xsd::cxx::xml::dom::auto_ptr<xercesc::DOMDocument>
+parse (std::istream& is,
+ const std::string& id,
+ bool validate);
+
+#endif // DOM_PARSE
diff --git a/examples/cxx/tree/messaging/dom-serialize.cxx b/examples/cxx/tree/messaging/dom-serialize.cxx
new file mode 100644
index 0000000..c0f4311
--- /dev/null
+++ b/examples/cxx/tree/messaging/dom-serialize.cxx
@@ -0,0 +1,89 @@
+// file : examples/cxx/tree/messaging/dom-serialize.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : not copyrighted - public domain
+
+#include "dom-serialize.hxx"
+
+#include <ostream>
+
+#include <xercesc/dom/DOM.hpp>
+#include <xercesc/util/XMLUniDefs.hpp>
+
+#include <xsd/cxx/xml/string.hxx>
+#include <xsd/cxx/xml/dom/auto-ptr.hxx>
+#include <xsd/cxx/xml/dom/serialization-source.hxx>
+#include <xsd/cxx/xml/dom/bits/error-handler-proxy.hxx>
+
+#include <xsd/cxx/tree/exceptions.hxx>
+#include <xsd/cxx/tree/error-handler.hxx>
+
+using namespace xercesc;
+namespace xml = xsd::cxx::xml;
+namespace tree = xsd::cxx::tree;
+
+void
+serialize (std::ostream& os,
+ const xercesc::DOMDocument& doc,
+ const std::string& encoding)
+{
+ const XMLCh ls_id [] = {chLatin_L, chLatin_S, chNull};
+
+ // Get an implementation of the Load-Store (LS) interface.
+ //
+ DOMImplementation* impl (
+ DOMImplementationRegistry::getDOMImplementation (ls_id));
+
+ tree::error_handler<char> eh;
+ xml::dom::bits::error_handler_proxy<char> ehp (eh);
+
+ xml::dom::ostream_format_target oft (os);
+
+#if _XERCES_VERSION >= 30000
+
+ // Create a DOMSerializer.
+ //
+ xml::dom::auto_ptr<DOMLSSerializer> writer (
+ impl->createLSSerializer ());
+
+ DOMConfiguration* conf (writer->getDomConfig ());
+
+ // Set error handler.
+ //
+ conf->setParameter (XMLUni::fgDOMErrorHandler, &ehp);
+
+ // Set some generally nice features.
+ //
+ conf->setParameter (XMLUni::fgDOMWRTDiscardDefaultContent, true);
+ conf->setParameter (XMLUni::fgDOMWRTFormatPrettyPrint, true);
+
+ xml::dom::auto_ptr<DOMLSOutput> out (impl->createLSOutput ());
+ out->setEncoding (xml::string (encoding).c_str ());
+ out->setByteStream (&oft);
+
+ writer->write (&doc, out.get ());
+
+#else
+
+ // Create a DOMWriter.
+ //
+ xml::dom::auto_ptr<DOMWriter> writer (impl->createDOMWriter ());
+
+ // Set error handler.
+ //
+ writer->setErrorHandler (&ehp);
+
+ // Set encoding.
+ //
+ writer->setEncoding(xml::string (encoding).c_str ());
+
+ // Set some generally nice features.
+ //
+ writer->setFeature (XMLUni::fgDOMWRTDiscardDefaultContent, true);
+ writer->setFeature (XMLUni::fgDOMWRTFormatPrettyPrint, true);
+
+ writer->writeNode (&oft, doc);
+
+#endif
+
+ eh.throw_if_failed<tree::serialization<char> > ();
+}
diff --git a/examples/cxx/tree/messaging/dom-serialize.hxx b/examples/cxx/tree/messaging/dom-serialize.hxx
new file mode 100644
index 0000000..1a7e855
--- /dev/null
+++ b/examples/cxx/tree/messaging/dom-serialize.hxx
@@ -0,0 +1,21 @@
+// file : examples/cxx/tree/messaging/dom-serialize.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : not copyrighted - public domain
+
+#ifndef DOM_SERIALIZE
+#define DOM_SERIALIZE
+
+#include <string>
+#include <iosfwd>
+
+#include <xercesc/dom/DOMDocument.hpp>
+
+// Serialize a DOM document to XML which is written to the standard
+// output stream.
+//
+void
+serialize (std::ostream& os,
+ const xercesc::DOMDocument& doc,
+ const std::string& encoding = "UTF-8");
+
+#endif // DOM_SERIALIZE
diff --git a/examples/cxx/tree/messaging/driver.cxx b/examples/cxx/tree/messaging/driver.cxx
new file mode 100644
index 0000000..4c36aa4
--- /dev/null
+++ b/examples/cxx/tree/messaging/driver.cxx
@@ -0,0 +1,145 @@
+// file : examples/cxx/tree/messaging/driver.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : not copyrighted - public domain
+
+#include <memory> // std::auto_ptr
+#include <string>
+#include <fstream>
+#include <typeinfo>
+#include <iostream>
+
+#include <xercesc/dom/DOM.hpp>
+#include <xercesc/util/PlatformUtils.hpp>
+
+#include <xsd/cxx/xml/string.hxx>
+
+#include "dom-parse.hxx"
+#include "dom-serialize.hxx"
+
+#include "protocol.hxx"
+
+using namespace std;
+using namespace protocol;
+using namespace xercesc;
+
+int
+main (int argc, char* argv[])
+{
+ if (argc != 2)
+ {
+ cerr << "usage: " << argv[0] << " request.xml" << endl;
+ return 1;
+ }
+
+ int r (0);
+
+ // We need to initialize the Xerces-C++ runtime because we
+ // are doing the XML-to-DOM parsing ourselves.
+ //
+ XMLPlatformUtils::Initialize ();
+
+ try
+ {
+ ifstream ifs;
+ ifs.exceptions (ifstream::badbit | ifstream::failbit);
+ ifs.open (argv[1]);
+
+ auto_ptr<xml_schema::element_type> req, res;
+
+ // Parse the XML request to a DOM document using the parse()
+ // function from dom-parse.hxx.
+ //
+ {
+ xml_schema::dom::auto_ptr<DOMDocument> doc (parse (ifs, argv[1], true));
+ DOMElement& root (*doc->getDocumentElement ());
+
+ req = xml_schema::element_map::parse (root);
+ }
+
+ // We can test which request we've got either using RTTI or by
+ // comparing the element names, as shown below.
+ //
+ if (balance* b = dynamic_cast<balance*> (req.get ()))
+ {
+ account_t& a (b->value ());
+
+ cerr << "balance request for acc# " << a.account () << endl;
+
+ res.reset (new success (balance_t (a.account (), 1000)));
+ }
+ else if (req->_name () == withdraw::name ())
+ {
+ withdraw& w (static_cast<withdraw&> (*req));
+ change_t& c (w.value ());
+
+ wcerr << "withdrawal request for acc# " << c.account () << ", "
+ << "amount: " << c.amount () << endl;
+
+ if (c.amount () > 1000)
+ res.reset (new insufficient_funds (balance_t (c.account (), 1000)));
+ else
+ res.reset (new success (balance_t (c.account (), 1000 - c.amount ())));
+
+ }
+ else if (req->_name () == deposit::name ())
+ {
+ deposit& d (static_cast<deposit&> (*req));
+ change_t& c (d.value ());
+
+ wcerr << "deposit request for acc# " << c.account () << ", "
+ << "amount: " << c.amount () << endl;
+
+ res.reset (new success (balance_t (c.account (), 1000 + c.amount ())));
+ }
+
+ // Serialize the response to a DOM document.
+ //
+ namespace xml = xsd::cxx::xml;
+
+ const XMLCh ls_id [] = {chLatin_L, chLatin_S, chNull};
+
+ DOMImplementation* impl (
+ DOMImplementationRegistry::getDOMImplementation (ls_id));
+
+ const string& name (res->_name ());
+ const string& ns (res->_namespace ());
+
+ xml_schema::dom::auto_ptr<DOMDocument> doc (
+ impl->createDocument (
+ xml::string (ns).c_str (),
+ xml::string ("p:" + name).c_str (),
+ 0));
+
+ xml_schema::element_map::serialize (*doc->getDocumentElement (), *res);
+
+ // Serialize the DOM document to XML using the serialize() function
+ // from dom-serialize.hxx.
+ //
+ cout << "response:" << endl
+ << endl;
+
+ serialize (cout, *doc);
+ }
+ catch (const xml_schema::no_element_info& e)
+ {
+ // This exception indicates that we tried to parse or serialize
+ // an unknown element.
+ //
+ cerr << "unknown request: " << e.element_namespace () << "#" <<
+ e.element_name () << endl;
+ r = 1;
+ }
+ catch (const xml_schema::exception& e)
+ {
+ cerr << e << endl;
+ r = 1;
+ }
+ catch (const std::ios_base::failure&)
+ {
+ cerr << argv[1] << ": unable to open or read failure" << endl;
+ r = 1;
+ }
+
+ XMLPlatformUtils::Terminate ();
+ return r;
+}
diff --git a/examples/cxx/tree/messaging/makefile b/examples/cxx/tree/messaging/makefile
new file mode 100644
index 0000000..2f4c7fe
--- /dev/null
+++ b/examples/cxx/tree/messaging/makefile
@@ -0,0 +1,72 @@
+# file : examples/cxx/tree/messaging/makefile
+# author : Boris Kolpackov <boris@codesynthesis.com>
+# copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC
+# license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make
+
+xsd := protocol.xsd
+cxx := driver.cxx dom-parse.cxx dom-serialize.cxx
+
+obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=.o))
+dep := $(obj:.o=.o.d)
+
+driver := $(out_base)/driver
+clean := $(out_base)/.clean
+
+
+# Import.
+#
+$(call import,\
+ $(scf_root)/import/libxerces-c/stub.make,\
+ l: xerces_c.l,cpp-options: xerces_c.l.cpp-options)
+
+
+# Build.
+#
+$(driver): $(obj) $(xerces_c.l)
+
+$(obj) $(dep): cpp_options := -I$(src_root)/libxsd
+$(obj) $(dep): $(xerces_c.l.cpp-options)
+
+$(out_base)/$(xsd:.xsd=.hxx) \
+$(out_base)/$(xsd:.xsd=.ixx) \
+$(out_base)/$(xsd:.xsd=.cxx): xsd := $(out_root)/xsd/xsd
+
+$(out_base)/$(xsd:.xsd=.hxx) \
+$(out_base)/$(xsd:.xsd=.ixx) \
+$(out_base)/$(xsd:.xsd=.cxx): xsd_options := --root-element-all \
+--generate-element-type --generate-element-map --generate-serialization
+
+$(out_base)/$(xsd:.xsd=.hxx) \
+$(out_base)/$(xsd:.xsd=.ixx) \
+$(out_base)/$(xsd:.xsd=.cxx): $(out_root)/xsd/xsd
+
+$(call include-dep,$(dep))
+
+# Convenience alias for default target.
+#
+.PHONY: $(out_base)/
+$(out_base)/: $(driver)
+
+
+# Clean.
+#
+.PHONY: $(clean)
+
+$(clean): $(driver).o.clean \
+ $(addsuffix .cxx.clean,$(obj)) \
+ $(addsuffix .cxx.clean,$(dep)) \
+ $(addprefix $(out_base)/,$(xsd:.xsd=.cxx.xsd.clean))
+
+
+# How to.
+#
+$(call include,$(bld_root)/cxx/o-e.make)
+$(call include,$(bld_root)/cxx/cxx-o.make)
+$(call include,$(bld_root)/cxx/cxx-d.make)
+$(call include,$(scf_root)/xsd/tree/xsd-cxx.make)
+
+# Dependencies.
+#
+$(call import,$(src_root)/xsd/makefile)
diff --git a/examples/cxx/tree/messaging/protocol.xsd b/examples/cxx/tree/messaging/protocol.xsd
new file mode 100644
index 0000000..3461133
--- /dev/null
+++ b/examples/cxx/tree/messaging/protocol.xsd
@@ -0,0 +1,54 @@
+<?xml version="1.0"?>
+
+<!--
+
+file : examples/cxx/tree/messaging/protocol.xsd
+author : Boris Kolpackov <boris@codesynthesis.com>
+copyright : not copyrighted - public domain
+
+-->
+
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:p="http://www.codesynthesis.com/protocol"
+ targetNamespace="http://www.codesynthesis.com/protocol">
+
+ <!-- types -->
+
+ <xsd:complexType name="account_t">
+ <xsd:sequence>
+ <xsd:element name="account" type="xsd:unsignedInt"/>
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:complexType name="change_t">
+ <xsd:complexContent>
+ <xsd:extension base="p:account_t">
+ <xsd:sequence>
+ <xsd:element name="amount" type="xsd:unsignedInt"/>
+ </xsd:sequence>
+ </xsd:extension>
+ </xsd:complexContent>
+ </xsd:complexType>
+
+ <xsd:complexType name="balance_t">
+ <xsd:complexContent>
+ <xsd:extension base="p:account_t">
+ <xsd:sequence>
+ <xsd:element name="balance" type="xsd:unsignedInt"/>
+ </xsd:sequence>
+ </xsd:extension>
+ </xsd:complexContent>
+ </xsd:complexType>
+
+ <!-- request elements -->
+
+ <xsd:element name="balance" type="p:account_t"/>
+ <xsd:element name="withdraw" type="p:change_t"/>
+ <xsd:element name="deposit" type="p:change_t"/>
+
+ <!-- response elements -->
+
+ <xsd:element name="success" type="p:balance_t"/>
+ <xsd:element name="insufficient-funds" type="p:balance_t"/>
+
+</xsd:schema>
diff --git a/examples/cxx/tree/messaging/withdraw.xml b/examples/cxx/tree/messaging/withdraw.xml
new file mode 100644
index 0000000..16a7440
--- /dev/null
+++ b/examples/cxx/tree/messaging/withdraw.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0"?>
+
+<!--
+
+file : examples/cxx/tree/messaging/withdraw.xml
+author : Boris Kolpackov <boris@codesynthesis.com>
+copyright : not copyrighted - public domain
+
+-->
+
+<p:withdraw xmlns:p="http://www.codesynthesis.com/protocol"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.codesynthesis.com/protocol protocol.xsd">
+
+ <account>123456789</account>
+ <amount>1000000</amount>
+
+</p:withdraw>