aboutsummaryrefslogtreecommitdiff
path: root/examples/cxx/serializer/hello/driver.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'examples/cxx/serializer/hello/driver.cxx')
-rw-r--r--examples/cxx/serializer/hello/driver.cxx90
1 files changed, 90 insertions, 0 deletions
diff --git a/examples/cxx/serializer/hello/driver.cxx b/examples/cxx/serializer/hello/driver.cxx
new file mode 100644
index 0000000..e895add
--- /dev/null
+++ b/examples/cxx/serializer/hello/driver.cxx
@@ -0,0 +1,90 @@
+// file : examples/cxx/serializer/hello/driver.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : not copyrighted - public domain
+
+#include <string>
+#include <vector>
+#include <iostream>
+
+#include "hello-sskel.hxx"
+
+using namespace std;
+
+struct hello_simpl: hello_sskel
+{
+ hello_simpl ()
+ {
+ names_.push_back ("sun");
+ names_.push_back ("moon");
+ names_.push_back ("world");
+ }
+
+ virtual void
+ pre ()
+ {
+ i_ = names_.begin ();
+ }
+
+ virtual string
+ greeting ()
+ {
+ return "Hello";
+ }
+
+ virtual bool
+ name_next ()
+ {
+ return i_ != names_.end ();
+ }
+
+ virtual string
+ name ()
+ {
+ return *i_++;
+ }
+
+private:
+ typedef vector<string> names;
+
+ names names_;
+ names::iterator i_;
+};
+
+
+int
+main ()
+{
+ try
+ {
+ // Construct the serializer.
+ //
+ xml_schema::string_simpl string_s;
+ hello_simpl hello_s;
+
+ hello_s.greeting_serializer (string_s);
+ hello_s.name_serializer (string_s);
+
+
+ // Create the XML instance document. The second argument to the
+ // document's constructor is the document's root element name.
+ //
+ xml_schema::document_simpl doc_s (hello_s, "hello");
+ doc_s.add_no_namespace_schema ("hello.xsd");
+
+ hello_s.pre ();
+ doc_s.serialize (cout);
+ hello_s.post ();
+ }
+ catch (const xml_schema::serializer_exception& e)
+ {
+ cerr << "error: " << e.text () << endl;
+ return 1;
+ }
+ catch (const std::ios_base::failure&)
+ {
+ cerr << "error: write failure" << endl;
+ return 1;
+ }
+
+ return 0;
+}