aboutsummaryrefslogtreecommitdiff
path: root/examples/cxx/hybrid/wildcard
diff options
context:
space:
mode:
Diffstat (limited to 'examples/cxx/hybrid/wildcard')
-rw-r--r--examples/cxx/hybrid/wildcard/README76
-rw-r--r--examples/cxx/hybrid/wildcard/body.cxx26
-rw-r--r--examples/cxx/hybrid/wildcard/body.hxx81
-rw-r--r--examples/cxx/hybrid/wildcard/driver.cxx188
-rw-r--r--examples/cxx/hybrid/wildcard/email.xml31
-rw-r--r--examples/cxx/hybrid/wildcard/email.xsd45
-rw-r--r--examples/cxx/hybrid/wildcard/envelope-pimpl.cxx111
-rw-r--r--examples/cxx/hybrid/wildcard/envelope-pimpl.hxx81
-rw-r--r--examples/cxx/hybrid/wildcard/envelope-simpl.cxx137
-rw-r--r--examples/cxx/hybrid/wildcard/envelope-simpl.hxx67
-rw-r--r--examples/cxx/hybrid/wildcard/makefile80
11 files changed, 923 insertions, 0 deletions
diff --git a/examples/cxx/hybrid/wildcard/README b/examples/cxx/hybrid/wildcard/README
new file mode 100644
index 0000000..d54b081
--- /dev/null
+++ b/examples/cxx/hybrid/wildcard/README
@@ -0,0 +1,76 @@
+This example shows how to parse, store in the object model, and serialize
+XML data matched by XML Schema wildcards (any and anyAttribute) using the
+Embedded C++/Hybrid mapping.
+
+This example uses the object model as well as parser and serializer
+customization mechanisms provided by the C++/Hybrid mapping. For more
+information, see Section 4.8, "Customizing the Object Model" and Section
+6.1, "Customizing Parsers and Serializers" in the Embedded C++/Hybrid
+Mapping Getting Started Guide.
+
+The example consists of the following files:
+
+email.xsd
+ XML Schema which describes a simple email format with the
+ extensible envelope type.
+
+email.xml
+ Sample email message.
+
+email.hxx
+email.cxx
+
+email-pskel.hxx
+email-pskel.cxx
+email-pimpl.hxx
+email-pimpl.cxx
+
+email-pskel.hxx
+email-pskel.cxx
+email-pimpl.hxx
+email-pimpl.cxx
+ Object model (the first pair of files), parser skeletons (the
+ second pair), parser implementations (the third pair), serializer
+ skeletons (the fourth pair), and serializer implementations (the
+ fifth pair). These files are generated by the XSD/e compiler from
+ email.xsd. The --generate-parser, --generate-serializer, and
+ --generate-aggregate options were used to request the generation of
+ the parsing and serialization code. The --custom-data option was
+ used to request addition of custom data to the envelope class in
+ the object model. The --custom-parser option was used to customize
+ the envelope_pimpl parser implementation. The --custom-serializer
+ option was used to customize the envelope_simpl serializer
+ implementation.
+
+body.hxx
+body.cxx
+ Implementation of the body class. It is used to store the wildcard
+ data in the custom data sequence in the envelope class.
+
+envelope-pimpl.hxx
+envelope-pimpl.cxx
+ Custom envelope parser implementation. It uses the implementation
+ generated by the XSD/e compiler as a base and overrides the wildcard
+ callbacks to parse the wildcard content and store it as custom data
+ in the envelope object.
+
+envelope-simpl.hxx
+envelope-simpl.cxx
+ Custom envelope serializer implementation. It uses the implementation
+ generated by the XSD/e compiler as a base and overrides the wildcard
+ callbacks to serialize the wildcard content stored as custom data in
+ the envelope object.
+
+driver.cxx
+ Driver for the example. It first calls the parser that constructs the
+ email object from the input XML file. It then prints the content of
+ the email to STDERR. Finally, the driver creates a reply email and
+ calls the serializer to serialize it to XML.
+
+To run the example on the sample XML instance document simply execute:
+
+$ ./driver email.xml
+
+The example reads from STDIN if input file is not specified:
+
+$ ./driver <email.xml
diff --git a/examples/cxx/hybrid/wildcard/body.cxx b/examples/cxx/hybrid/wildcard/body.cxx
new file mode 100644
index 0000000..e6bd164
--- /dev/null
+++ b/examples/cxx/hybrid/wildcard/body.cxx
@@ -0,0 +1,26 @@
+// file : examples/cxx/hybrid/wildcard/body.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : not copyrighted - public domain
+
+#include "body.hxx"
+
+namespace email
+{
+ void body::
+ body_type (body::type t)
+ {
+ if (body_type_ == type_binary)
+ {
+ delete binary_;
+ binary_ = 0;
+ }
+
+ body_type_ = t;
+ }
+
+ void
+ destroy_body (void* p, size_t)
+ {
+ delete static_cast<body*> (p);
+ }
+}
diff --git a/examples/cxx/hybrid/wildcard/body.hxx b/examples/cxx/hybrid/wildcard/body.hxx
new file mode 100644
index 0000000..512a107
--- /dev/null
+++ b/examples/cxx/hybrid/wildcard/body.hxx
@@ -0,0 +1,81 @@
+// file : examples/cxx/hybrid/wildcard/body.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : not copyrighted - public domain
+
+#ifndef BODY_HXX
+#define BODY_HXX
+
+#include "email.hxx"
+
+namespace email
+{
+ // Custom email body type which can hold text or binary.
+ //
+ class body
+ {
+ public:
+ enum type
+ {
+ type_none,
+ type_text,
+ type_binary
+ };
+
+ body ()
+ : body_type_ (type_none), binary_ (0)
+ {
+ }
+
+ ~body ()
+ {
+ body_type (type_none);
+ }
+
+ type
+ body_type () const
+ {
+ return body_type_;
+ }
+
+ const std::string&
+ text () const
+ {
+ return text_;
+ }
+
+ void
+ text (const std::string& t)
+ {
+ body_type (type_text);
+ text_ = t;
+ }
+
+ const email::binary&
+ binary () const
+ {
+ return *binary_;
+ }
+
+ void
+ binary (email::binary* b)
+ {
+ body_type (type_binary);
+ binary_ = b;
+ }
+
+ private:
+ void
+ body_type (type t);
+
+ type body_type_;
+ std::string text_;
+ email::binary* binary_;
+ };
+
+ // Custom data destructor for body.
+ //
+ void
+ destroy_body (void*, size_t);
+}
+
+#endif // BODY_HXX
diff --git a/examples/cxx/hybrid/wildcard/driver.cxx b/examples/cxx/hybrid/wildcard/driver.cxx
new file mode 100644
index 0000000..eea5bc7
--- /dev/null
+++ b/examples/cxx/hybrid/wildcard/driver.cxx
@@ -0,0 +1,188 @@
+// file : examples/cxx/hybrid/wildcard/driver.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : not copyrighted - public domain
+
+#include <string> // memcpy
+#include <memory> // std::auto_ptr
+#include <iostream>
+
+#include "email.hxx"
+#include "body.hxx"
+
+#include "email-pimpl.hxx"
+#include "email-simpl.hxx"
+
+using namespace std;
+
+// Extended parser and serializer aggregates for the message
+// element. They add parser/serializer aggregates for the
+// wildcard elements.
+//
+namespace email
+{
+ class message_paggr_ex: public message_paggr
+ {
+ public:
+ message_paggr_ex ()
+ {
+ envelope_p_.text_parser (text_p_.root_parser ());
+ envelope_p_.binary_parser (binary_p_.root_parser ());
+ }
+
+ public:
+ text_paggr text_p_;
+ binary_paggr binary_p_;
+ };
+
+ class message_saggr_ex: public message_saggr
+ {
+ public:
+ message_saggr_ex ()
+ {
+ envelope_s_.text_serializer (text_s_.root_serializer ());
+ envelope_s_.binary_serializer (binary_s_.root_serializer ());
+ }
+
+ public:
+ text_saggr text_s_;
+ binary_saggr binary_s_;
+ };
+}
+
+int
+main (int argc, char* argv[])
+{
+ const char* input;
+
+ if (argc < 2)
+ {
+ input = "STDIN";
+ cerr << "XML file not specified, reading from STDIN" << endl;
+ }
+ else
+ input = argv[1];
+
+ try
+ {
+ using namespace email;
+
+ // Parse.
+ //
+ message_paggr_ex message_p;
+
+ xml_schema::document_pimpl doc_p (
+ message_p.root_parser (),
+ message_p.root_namespace (),
+ message_p.root_name ());
+
+ message_p.pre ();
+
+ if (argc < 2)
+ doc_p.parse (cin);
+ else
+ doc_p.parse (argv[1]);
+
+ auto_ptr<envelope> msg (message_p.post ());
+
+ // Print what we've got.
+ //
+ cerr << "To: " << msg->to () << endl
+ << "From: " << msg->from () << endl
+ << "Subject: " << msg->subject () << endl;
+
+ envelope::custom_data_sequence& body_seq (msg->custom_data ());
+
+ for (envelope::custom_data_iterator i = body_seq.begin ();
+ i != body_seq.end ();
+ ++i)
+ {
+ body* b = static_cast<body*> (*i);
+
+ switch (b->body_type ())
+ {
+ case body::type_text:
+ {
+ cerr << b->text () << endl
+ << endl;
+ break;
+ }
+ case body::type_binary:
+ {
+ const binary& bin = b->binary ();
+ cerr << "binary: " << bin.name () << " "
+ << "type: " << bin.mime () << endl
+ << endl;
+ break;
+ }
+ default:
+ {
+ cerr << "unexpected body type" << endl;
+ break;
+ }
+ }
+ }
+
+ // Create a reply message.
+ //
+ auto_ptr<envelope> reply (new envelope);
+ reply->custom_data ().destructor (&destroy_body);
+
+ reply->to (msg->from ());
+ reply->from (msg->to ());
+ reply->subject ("Re: " + msg->subject ());
+
+ // Add a text body.
+ //
+ auto_ptr<body> b (new body);
+ b->text ("Hi!\n\n"
+ "Indeed nice pictures. Check out mine.\n\n"
+ "Jane");
+ reply->custom_data ().push_back (b.release ());
+
+ // Add a (fake) image.
+ //
+ auto_ptr<binary> pic (new binary);
+ pic->name ("pic.jpg");
+ pic->mime ("image/jpeg");
+ pic->size (3);
+ memcpy (pic->data (), "123", 3);
+
+ b = auto_ptr<body> (new body);
+ b->binary (pic.release ());
+ reply->custom_data ().push_back (b.release ());
+
+ // Serialize.
+ //
+ message_saggr_ex message_s;
+
+ xml_schema::document_simpl doc_s (
+ message_s.root_serializer (),
+ message_s.root_namespace (),
+ message_s.root_name ());
+
+ doc_s.add_prefix ("lib", "http://www.codesynthesis.com/email");
+ doc_s.add_schema ("http://www.codesynthesis.com/email", "email.xsd");
+
+ message_s.pre (*reply);
+ doc_s.serialize (cout);
+ message_s.post ();
+ }
+ catch (const xml_schema::parser_exception& e)
+ {
+ cerr << input << ":" << e.line () << ":" << e.column () << ": "
+ << e.text () << endl;
+ return 1;
+ }
+ catch (const xml_schema::serializer_exception& e)
+ {
+ cerr << "error: " << e.text () << endl;
+ return 1;
+ }
+ catch (const std::ios_base::failure&)
+ {
+ cerr << input << ": unable to open or read/write failure" << endl;
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/examples/cxx/hybrid/wildcard/email.xml b/examples/cxx/hybrid/wildcard/email.xml
new file mode 100644
index 0000000..75592f4
--- /dev/null
+++ b/examples/cxx/hybrid/wildcard/email.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0"?>
+
+<!--
+
+file : examples/cxx/hybrid/wildcard/email.xml
+author : Boris Kolpackov <boris@codesynthesis.com>
+copyright : not copyrighted - public domain
+
+-->
+
+<eml:message xmlns:eml="http://www.codesynthesis.com/email"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.codesynthesis.com/email email.xsd">
+
+ <to>Jane Doe &lt;jane@doe.com></to>
+ <from>John Doe &lt;john@doe.com></from>
+ <subject>Surfing pictures</subject>
+
+ <eml:text>
+Hi Jane,
+
+Here are cool pictures of me surfing.
+
+Cheers,
+John
+ </eml:text>
+
+ <eml:binary name="pic1.jpg" mime="image/jpeg">YmFzZTY0IGJpbmFyeQ==</eml:binary>
+ <eml:binary name="pic2.jpg" mime="image/jpeg">YmFzZTY0IGJpbmFyeQ==</eml:binary>
+
+</eml:message>
diff --git a/examples/cxx/hybrid/wildcard/email.xsd b/examples/cxx/hybrid/wildcard/email.xsd
new file mode 100644
index 0000000..ca20df3
--- /dev/null
+++ b/examples/cxx/hybrid/wildcard/email.xsd
@@ -0,0 +1,45 @@
+<?xml version="1.0"?>
+
+<!--
+
+file : examples/cxx/hybrid/wildcard/email.xsd
+author : Boris Kolpackov <boris@codesynthesis.com>
+copyright : not copyrighted - public domain
+
+-->
+
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:eml="http://www.codesynthesis.com/email"
+ targetNamespace="http://www.codesynthesis.com/email">
+
+ <!-- Predefined envolop body types. -->
+
+ <xsd:element name="text" type="xsd:string"/>
+
+ <xsd:complexType name="binary">
+ <xsd:simpleContent>
+ <xsd:extension base="xsd:base64Binary">
+ <xsd:attribute name="name" type="xsd:string" use="required"/>
+ <xsd:attribute name="mime" type="xsd:string" use="required"/>
+ </xsd:extension>
+ </xsd:simpleContent>
+ </xsd:complexType>
+
+ <xsd:element name="binary" type="eml:binary"/>
+
+ <xsd:complexType name="envelope">
+ <xsd:sequence>
+ <xsd:element name="to" type="xsd:string"/>
+ <xsd:element name="from" type="xsd:string"/>
+ <xsd:element name="subject" type="xsd:string"/>
+
+ <!-- Extensible envelope body. -->
+
+ <xsd:any namespace="##targetNamespace" processContents="strict"
+ maxOccurs="unbounded" />
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:element name="message" type="eml:envelope"/>
+
+</xsd:schema>
diff --git a/examples/cxx/hybrid/wildcard/envelope-pimpl.cxx b/examples/cxx/hybrid/wildcard/envelope-pimpl.cxx
new file mode 100644
index 0000000..16bd2e5
--- /dev/null
+++ b/examples/cxx/hybrid/wildcard/envelope-pimpl.cxx
@@ -0,0 +1,111 @@
+// file : examples/cxx/hybrid/wildcard/envelope-pimpl.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : not copyrighted - public domain
+
+#include <memory> // std::auto_ptr
+
+#include "body.hxx"
+
+// Include email-pimpl.hxx (which includes envelope-pimpl.hxx)
+// instead of envelope-pimpl.hxx.
+//
+#include "email-pimpl.hxx"
+
+namespace email
+{
+ void envelope_pimpl::
+ _pre ()
+ {
+ // Set the custom data destructor.
+ //
+ envelope_base_pimpl_state_.envelope_->custom_data ().destructor (
+ &destroy_body);
+
+ envelope_base_pimpl::_pre ();
+ }
+
+ void envelope_pimpl::
+#ifndef XSDE_POLYMORPHIC
+ _start_any_element (const xml_schema::ro_string& ns,
+ const xml_schema::ro_string& name)
+#else
+ _start_any_element (const xml_schema::ro_string& ns,
+ const xml_schema::ro_string& name,
+ const char*)
+#endif
+ {
+ // We use the depth_ counter to filter out nested elements
+ // and attributes for the content matched by the wildcard
+ // but which we don't know how to handle.
+ //
+ if (depth_++ == 0)
+ {
+ // Top-level (relative to this type) element matched by the
+ // any wildcard.
+ //
+ xml_schema::parser_base* p = 0;
+
+ if (ns == "http://www.codesynthesis.com/email")
+ {
+ if (name == "text")
+ p = text_p_;
+ else if (name == "binary")
+ p = binary_p_;
+
+ if (p != 0)
+ {
+ // If you are not using exceptions then you will need to add
+ // error propagation code. For more information on how to do
+ // this see the wildcard example for the C++/Parser mapping
+ // (examples/parser/ directory).
+ //
+ xml_schema::parser_context& ctx = _context ();
+ p->pre ();
+ p->_pre_impl (ctx);
+ }
+ }
+ }
+ }
+
+ void envelope_pimpl::
+ _end_any_element (const xml_schema::ro_string& ns,
+ const xml_schema::ro_string& name)
+ {
+ if (--depth_ == 0)
+ {
+ if (ns == "http://www.codesynthesis.com/email")
+ {
+ // Note that we don't call _post_impl() (corresponding to
+ // _pre_impl()) here. It is called automatically by the
+ // infrastructure.
+ //
+ envelope* env = envelope_base_pimpl_state_.envelope_;
+
+ if (name == "text")
+ {
+ std::auto_ptr<body> b (new body);
+ b->text (text_p_->post_string ());
+ env->custom_data ().push_back (b.release ());
+ }
+ else if (name == "binary")
+ {
+ std::auto_ptr<body> b (new body);
+ b->binary (binary_p_->post_binary ());
+ env->custom_data ().push_back (b.release ());
+ }
+ }
+ }
+ }
+
+ void envelope_pimpl::
+ _reset ()
+ {
+ // Note that we always need to call _reset() from the base.
+ //
+ envelope_base_pimpl::_reset ();
+
+ depth_ = 0;
+ text_p_->_reset ();
+ binary_p_->_reset ();
+ }
+}
diff --git a/examples/cxx/hybrid/wildcard/envelope-pimpl.hxx b/examples/cxx/hybrid/wildcard/envelope-pimpl.hxx
new file mode 100644
index 0000000..06eb26c
--- /dev/null
+++ b/examples/cxx/hybrid/wildcard/envelope-pimpl.hxx
@@ -0,0 +1,81 @@
+// file : examples/cxx/hybrid/wildcard/envelope-pimpl.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : not copyrighted - public domain
+
+#ifndef ENVELOPE_PIMPL_HXX
+#define ENVELOPE_PIMPL_HXX
+
+namespace email
+{
+ // Customized envelope parser implementation. All wildcard events are
+ // routed to the _start_any_element, _end_any_element, _any_attribute,
+ // and _any_characters functions. We can dynamically select a parser
+ // from the _start_any_element after which all inner content will be
+ // automatically routed to this parser. At the end we will get a call
+ // to _end_any_element in which we can call post(), and save the data.
+ //
+ class envelope_pimpl: public envelope_base_pimpl
+ {
+ public:
+ envelope_pimpl ()
+ : depth_ (0), text_p_ (0), binary_p_ (0)
+ {
+ }
+
+ // Additional parsers for the wildcard content.
+ //
+ void
+ text_parser (xml_schema::string_pskel& p)
+ {
+ text_p_ = &p;
+ }
+
+ void
+ binary_parser (binary_pskel& p)
+ {
+ binary_p_ = &p;
+ }
+
+ public:
+ virtual void
+ _pre ();
+
+ // If the XSD runtime library was configured with polymorphism
+ // support, then _start_any_element has a third argument which
+ // is a dynamic type id that comes from xsi:type or substitution
+ // groups.
+ //
+#ifndef XSDE_POLYMORPHIC
+ virtual void
+ _start_any_element (const xml_schema::ro_string& ns,
+ const xml_schema::ro_string& name);
+#else
+ virtual void
+ _start_any_element (const xml_schema::ro_string& ns,
+ const xml_schema::ro_string& name,
+ const char*);
+#endif
+
+ virtual void
+ _end_any_element (const xml_schema::ro_string& ns,
+ const xml_schema::ro_string& name);
+
+ // If we need to be able to reset and reuse the parser after
+ // an error then we also need to override _reset() and reset
+ // the parsers that are used to handle wildcards.
+ //
+ virtual void
+ _reset ();
+
+ private:
+ std::size_t depth_;
+
+ // Parsers for the text and binary elements.
+ //
+ private:
+ xml_schema::string_pskel* text_p_;
+ binary_pskel* binary_p_;
+ };
+}
+
+#endif // ENVELOPE_PIMPL_HXX
diff --git a/examples/cxx/hybrid/wildcard/envelope-simpl.cxx b/examples/cxx/hybrid/wildcard/envelope-simpl.cxx
new file mode 100644
index 0000000..ae7bd00
--- /dev/null
+++ b/examples/cxx/hybrid/wildcard/envelope-simpl.cxx
@@ -0,0 +1,137 @@
+// file : examples/cxx/hybrid/wildcard/envelope-simpl.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : not copyrighted - public domain
+
+#include "body.hxx"
+
+// Include email-simpl.hxx (which includes envelope-simpl.hxx)
+// instead of envelope-simpl.hxx.
+//
+#include "email-simpl.hxx"
+
+namespace email
+{
+ void envelope_simpl::
+ _pre ()
+ {
+ // Initialize the body iterator.
+ //
+ i_ = envelope_base_simpl_state_.envelope_->custom_data ().begin ();
+ }
+
+ bool envelope_simpl::
+ any_next ()
+ {
+ envelope::custom_data_const_iterator end (
+ envelope_base_simpl_state_.envelope_->custom_data ().end ());
+
+ // See if there is a body that we know how to serialize.
+ //
+ for (; i_ != end; ++i_)
+ {
+ body::type t = static_cast<const body*> (*i_)->body_type ();
+
+ if (t == body::type_text || t == body::type_binary)
+ break;
+ }
+
+ return i_ != end;
+ }
+
+ void envelope_simpl::
+ any (std::string& ns, std::string& name)
+ {
+ ns = "http://www.codesynthesis.com/email";
+
+ switch (static_cast<const body*> (*i_)->body_type ())
+ {
+ case body::type_text:
+ {
+ name = "text";
+ break;
+ }
+ case body::type_binary:
+ {
+ name = "binary";
+ break;
+ }
+ default:
+ break;
+ }
+ }
+
+ void envelope_simpl::
+ serialize_any ()
+ {
+ xml_schema::serializer_base* s = 0;
+ const body* b = static_cast<const body*> (*i_++);
+
+ // If you are not using exceptions then you will need to add
+ // error propagation code. For more information on how to do
+ // this see the wildcard example for the C++/Parser mapping
+ // (examples/parser/ directory).
+ //
+ switch (b->body_type ())
+ {
+ case body::type_text:
+ {
+ text_s_->pre (b->text ());
+ s = text_s_;
+ break;
+ }
+ case body::type_binary:
+ {
+ binary_s_->pre (b->binary ());
+ s = binary_s_;
+ break;
+ }
+ default:
+ break;
+ }
+
+ if (s != 0)
+ {
+ // If XML Schema validation is enabled then we need to check
+ // for error conditions.
+ //
+ xml_schema::serializer_context& ctx = _context ();
+
+ s->_pre_impl (ctx);
+
+#ifdef XSDE_SERIALIZER_VALIDATION
+ if (ctx.error_type ())
+ return;
+#endif
+ s->_serialize_attributes ();
+
+#ifdef XSDE_SERIALIZER_VALIDATION
+ if (ctx.error_type ())
+ return;
+#endif
+ s->_serialize_content ();
+
+#ifdef XSDE_SERIALIZER_VALIDATION
+ if (ctx.error_type ())
+ return;
+#endif
+ s->_post_impl ();
+
+#ifdef XSDE_SERIALIZER_VALIDATION
+ if (ctx.error_type ())
+ return;
+#endif
+ s->post ();
+ }
+ }
+
+ void envelope_simpl::
+ _reset ()
+ {
+ text_s_->_reset ();
+ binary_s_->_reset ();
+
+ // Note that we always need to call _reset() from the base.
+ //
+ envelope_base_simpl::_reset ();
+ }
+}
diff --git a/examples/cxx/hybrid/wildcard/envelope-simpl.hxx b/examples/cxx/hybrid/wildcard/envelope-simpl.hxx
new file mode 100644
index 0000000..1de12bd
--- /dev/null
+++ b/examples/cxx/hybrid/wildcard/envelope-simpl.hxx
@@ -0,0 +1,67 @@
+// file : examples/cxx/hybrid/wildcard/envelope-simpl.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : not copyrighted - public domain
+
+#ifndef ENVELOPE_SIMPL_HXX
+#define ENVELOPE_SIMPL_HXX
+
+namespace email
+{
+ // Customized envelope serializer implementation. Here we implement
+ // the any_next, any, and serialize_any callbacks to serialize the
+ // wildcard content.
+ //
+ class envelope_simpl: public envelope_base_simpl
+ {
+ public:
+ envelope_simpl ()
+ : text_s_ (0), binary_s_ (0)
+ {
+ }
+
+ // Additional serializers for the wildcard content.
+ //
+ void
+ text_serializer (xml_schema::string_sskel& s)
+ {
+ text_s_ = &s;
+ }
+
+ void
+ binary_serializer (binary_sskel& s)
+ {
+ binary_s_ = &s;
+ }
+
+ public:
+ virtual void
+ _pre ();
+
+ virtual bool
+ any_next ();
+
+ virtual void
+ any (std::string& ns, std::string& name);
+
+ virtual void
+ serialize_any ();
+
+ // If we need to be able to reset and reuse the serializer
+ // after an error then we also need to override _reset() and
+ // reset the serializers that are used to handle wildcards.
+ //
+ virtual void
+ _reset ();
+
+ private:
+ envelope::custom_data_const_iterator i_;
+
+ // Serializers for the text and binary elements.
+ //
+ private:
+ xml_schema::string_sskel* text_s_;
+ binary_sskel* binary_s_;
+ };
+}
+
+#endif // ENVELOPE_SIMPL_HXX
diff --git a/examples/cxx/hybrid/wildcard/makefile b/examples/cxx/hybrid/wildcard/makefile
new file mode 100644
index 0000000..94d2fae
--- /dev/null
+++ b/examples/cxx/hybrid/wildcard/makefile
@@ -0,0 +1,80 @@
+# file : examples/cxx/hybrid/wildcard/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 := email.xsd
+cxx := driver.cxx body.cxx envelope-pimpl.cxx envelope-simpl.cxx
+
+obj := $(addprefix $(out_base)/,\
+$(cxx:.cxx=.o) \
+$(xsd:.xsd=.o) \
+$(xsd:.xsd=-pskel.o) \
+$(xsd:.xsd=-pimpl.o) \
+$(xsd:.xsd=-sskel.o) \
+$(xsd:.xsd=-simpl.o))
+
+dep := $(obj:.o=.o.d)
+
+xsde.l := $(out_root)/libxsde/xsde/xsde.l
+xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options
+
+driver := $(out_base)/driver
+clean := $(out_base)/.clean
+
+# Build.
+#
+$(driver): $(obj) $(xsde.l)
+
+$(obj) $(dep): $(xsde.l.cpp-options)
+
+gen := $(out_base)/$(xsd:.xsd=.hxx) \
+ $(out_base)/$(xsd:.xsd=.cxx) \
+ $(out_base)/$(xsd:.xsd=-pskel.hxx) \
+ $(out_base)/$(xsd:.xsd=-pskel.cxx) \
+ $(out_base)/$(xsd:.xsd=-pimpl.hxx) \
+ $(out_base)/$(xsd:.xsd=-pimpl.cxx) \
+ $(out_base)/$(xsd:.xsd=-sskel.hxx) \
+ $(out_base)/$(xsd:.xsd=-sskel.cxx) \
+ $(out_base)/$(xsd:.xsd=-simpl.hxx) \
+ $(out_base)/$(xsd:.xsd=-simpl.cxx)
+
+$(gen): $(out_root)/xsde/xsde
+$(gen): xsde := $(out_root)/xsde/xsde
+$(gen): xsde_options += --generate-parser --generate-serializer \
+--generate-aggregate --root-element-all --custom-data envelope \
+--custom-parser envelope=envelope_base_pimpl/envelope-pimpl.hxx \
+--custom-serializer envelope=envelope_base_simpl/envelope-simpl.hxx
+
+$(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)/xsde/hybrid/xsd-cxx.make)
+
+
+# Dependencies.
+#
+$(call import,$(src_root)/xsde/makefile)
+$(call import,$(src_root)/libxsde/xsde/makefile)