summaryrefslogtreecommitdiff
path: root/examples/cxx/tree/custom/mixed
diff options
context:
space:
mode:
Diffstat (limited to 'examples/cxx/tree/custom/mixed')
-rw-r--r--examples/cxx/tree/custom/mixed/README50
-rw-r--r--examples/cxx/tree/custom/mixed/driver.cxx123
-rw-r--r--examples/cxx/tree/custom/mixed/makefile114
-rw-r--r--examples/cxx/tree/custom/mixed/people-custom.cxx89
-rw-r--r--examples/cxx/tree/custom/mixed/people-custom.hxx83
-rw-r--r--examples/cxx/tree/custom/mixed/people.xml38
-rw-r--r--examples/cxx/tree/custom/mixed/people.xsd45
7 files changed, 0 insertions, 542 deletions
diff --git a/examples/cxx/tree/custom/mixed/README b/examples/cxx/tree/custom/mixed/README
deleted file mode 100644
index 7b56812..0000000
--- a/examples/cxx/tree/custom/mixed/README
+++ /dev/null
@@ -1,50 +0,0 @@
-This example shows how to use type customization to parse and serialize
-mixed content. The example achieves this by customizing the type with
-the mixed content model to include a DOM document that stores the data
-as a raw XML representation. The customized type also provides its own
-parsing constructor and serialization operator where the mixed content
-is extracted from and inserted back to DOM, respectively. The use of
-DOM for mixed content storage is one of the options. You may find other
-data structures (e.g., a string) more suitable depending on your situation.
-
-For more information on the C++/Tree mapping customization see the C++/Tree
-Mapping Customization Guide[1].
-
-[1] http://wiki.codesynthesis.com/Tree/Customization_guide
-
-The example consists of the following files:
-
-people.xsd
- XML Schema definition for a simple person record vocabulary. Each
- record includes the bio element which represents arbitrary XHTML
- fragments as mixed content.
-
-people.xml
- Sample XML instance document.
-
-people.hxx
-people.ixx
-people.cxx
- C++ types that represent the given vocabulary, a set of parsing
- functions that convert XML instance documents to a tree-like in-memory
- object model, and a set of serialization functions that convert the
- object model back to XML. These are generated by XSD from people.xsd
- with the --custom-type option in order to customize the bio type.
-
-people-custom.hxx
- Header file which defines our own bio class by inheriting from the
- generated bio_base. It is included at the end of people.hxx using
- the --hxx-epilogue option.
-
-people-custom.cxx
- Source file which contains the implementation of our bio class.
-
-driver.cxx
- Driver for the example. It first calls one of the parsing functions
- that constructs the object model from the input file. It then prints
- the data to STDERR, including the bio information converted to text.
- Finally, the driver serializes the object model back to XML.
-
-To run the example on the sample XML instance document simply execute:
-
-$ ./driver people.xml
diff --git a/examples/cxx/tree/custom/mixed/driver.cxx b/examples/cxx/tree/custom/mixed/driver.cxx
deleted file mode 100644
index 0378f18..0000000
--- a/examples/cxx/tree/custom/mixed/driver.cxx
+++ /dev/null
@@ -1,123 +0,0 @@
-// file : examples/cxx/tree/custom/mixed/driver.cxx
-// copyright : not copyrighted - public domain
-
-#include <memory> // std::auto_ptr
-#include <iostream>
-
-#include <xercesc/dom/DOM.hpp>
-#include <xercesc/util/PlatformUtils.hpp>
-
-#include "people.hxx"
-
-// The following transcode() utility function is handy when working with
-// Xerces. Include it after the generated header in order to get only char
-// or wchar_t version depending on how you compiled your schemas.
-//
-#include <xsd/cxx/xml/string.hxx>
-
-using std::cerr;
-using std::endl;
-using namespace xercesc;
-
-
-void
-xhtml2txt (const DOMElement*);
-
-int
-main (int argc, char* argv[])
-{
- if (argc != 2)
- {
- cerr << "usage: " << argv[0] << " people.xml" << endl;
- return 1;
- }
-
- int r (0);
-
- // The Xerces-C++ DOM document that will be used to store the XHTML
- // fragments "out-live" the call to the parsing function. Therefore
- // we need to initialize the Xerces-C++ runtime ourselves.
- //
- XMLPlatformUtils::Initialize ();
-
- try
- {
- using namespace people;
-
- // Parse.
- //
- std::auto_ptr<directory> d (
- directory_ (argv[1], xml_schema::flags::dont_initialize));
-
- // Print what we've got.
- //
- const directory::person_sequence& s (d->person ());
-
- for (directory::person_const_iterator i (s.begin ()); i != s.end (); ++i)
- {
- cerr << "First : " << i->first_name () << endl
- << "Last : " << i->last_name () << endl
- << "Gender : " << i->gender () << endl
- << "Age : " << i->age () << endl;
-
- const bio& b (i->bio ());
- const DOMElement* xhtml (b.xhtml ());
-
- if (xhtml != 0)
- {
- cerr << "Bio : " << endl;
- xhtml2txt (xhtml);
- }
-
- cerr << endl;
- }
-
- // Serialize.
- //
- xml_schema::namespace_infomap map;
-
- map["ppl"].name = "http://www.codesynthesis.com/people";
- map["ppl"].schema = "people.xsd";
-
- directory_ (
- std::cout, *d, map, "UTF-8", xml_schema::flags::dont_initialize);
- }
- catch (const xml_schema::exception& e)
- {
- cerr << e << endl;
- r = 1;
- }
-
- XMLPlatformUtils::Terminate ();
- return r;
-}
-
-// Primitive XHTML to text converter that just prints all the text
-// nodes and ignores everything else.
-//
-void
-xhtml2txt (const DOMElement* e)
-{
- namespace xml = xsd::cxx::xml;
-
- for (const DOMNode* n (e->getFirstChild ());
- n != 0;
- n = n->getNextSibling ())
- {
- switch (n->getNodeType ())
- {
- case DOMNode::TEXT_NODE:
- {
- cerr << xml::transcode<char> (n->getTextContent ());
- break;
- }
- case DOMNode::ELEMENT_NODE:
- {
- xhtml2txt (static_cast<const DOMElement*> (n));
- break;
- }
- default:
- break; // Ignore all other nodes (e.g., comments, etc).
- }
- }
-}
diff --git a/examples/cxx/tree/custom/mixed/makefile b/examples/cxx/tree/custom/mixed/makefile
deleted file mode 100644
index c191271..0000000
--- a/examples/cxx/tree/custom/mixed/makefile
+++ /dev/null
@@ -1,114 +0,0 @@
-# file : examples/cxx/tree/custom/mixed/makefile
-# license : GNU GPL v2 + exceptions; see accompanying LICENSE file
-
-include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../build/bootstrap.make
-
-xsd := people.xsd
-cxx := driver.cxx people-custom.cxx
-
-obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=.o))
-dep := $(obj:.o=.o.d)
-
-driver := $(out_base)/driver
-install := $(out_base)/.install
-dist := $(out_base)/.dist
-dist-win := $(out_base)/.dist-win
-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$(out_base) -I$(src_base) -I$(src_root)/libxsd
-$(obj) $(dep): $(xerces_c.l.cpp-options)
-
-genf := $(xsd:.xsd=.hxx) $(xsd:.xsd=.ixx) $(xsd:.xsd=.cxx)
-gen := $(addprefix $(out_base)/,$(genf))
-
-$(gen): xsd := $(out_root)/xsd/xsd
-
-# We have to double-escape '#' because the message function
-# (which is used in command scripts) expands things twice.
-#
-$(gen): xsd_options += \
---generate-inline \
---generate-serialization \
---custom-type bio=/bio_base \
---hxx-epilogue '\#include "people-custom.hxx"'
-
-$(gen): $(out_root)/xsd/xsd
-
-$(call include-dep,$(dep),$(obj),$(gen))
-
-# Convenience alias for default target.
-#
-$(out_base)/: $(driver)
-
-
-# Install & Dist.
-#
-dist-common := $(out_base)/.dist-common
-
-$(install) $(dist) $(dist-win) $(dist-common): path := $(subst $(src_root)/,,$(src_base))
-
-$(install):
- $(call install-data,$(src_base)/README,$(install_doc_dir)/xsd/$(path)/README)
- $(call install-data,$(src_base)/driver.cxx,$(install_doc_dir)/xsd/$(path)/driver.cxx)
- $(call install-data,$(src_base)/people.xsd,$(install_doc_dir)/xsd/$(path)/people.xsd)
- $(call install-data,$(src_base)/people.xml,$(install_doc_dir)/xsd/$(path)/people.xml)
- $(call install-data,$(src_base)/people-custom.hxx,$(install_doc_dir)/xsd/$(path)/people-custom.hxx)
- $(call install-data,$(src_base)/people-custom.cxx,$(install_doc_dir)/xsd/$(path)/people-custom.cxx)
-
-$(dist-common):
- $(call install-data,$(src_base)/driver.cxx,$(dist_prefix)/$(path)/driver.cxx)
- $(call install-data,$(src_base)/people.xsd,$(dist_prefix)/$(path)/people.xsd)
- $(call install-data,$(src_base)/people.xml,$(dist_prefix)/$(path)/people.xml)
- $(call install-data,$(src_base)/people-custom.hxx,$(dist_prefix)/$(path)/people-custom.hxx)
- $(call install-data,$(src_base)/people-custom.cxx,$(dist_prefix)/$(path)/people-custom.cxx)
-
-$(dist): $(dist-common)
- $(call install-data,$(src_base)/README,$(dist_prefix)/$(path)/README)
-
-$(dist-win): $(dist-common)
- $(call install-data,$(src_base)/README,$(dist_prefix)/$(path)/README.txt)
- $(call message,,todos $(dist_prefix)/$(path)/README.txt)
-
-
-# Clean.
-#
-$(clean): $(driver).o.clean \
- $(addsuffix .cxx.clean,$(obj)) \
- $(addsuffix .cxx.clean,$(dep)) \
- $(addprefix $(out_base)/,$(xsd:.xsd=.cxx.xsd.clean))
-
-# Generated .gitignore.
-#
-ifeq ($(out_base),$(src_base))
-$(gen): | $(out_base)/.gitignore
-$(driver): | $(out_base)/.gitignore
-
-$(out_base)/.gitignore: files := driver $(genf)
-$(clean): $(out_base)/.gitignore.clean
-
-$(call include,$(bld_root)/git/gitignore.make)
-endif
-
-# 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,$(bld_root)/install.make)
-$(call include,$(scf_root)/xsd/tree/xsd-cxx.make)
-
-# Dependencies.
-#
-$(call import,$(src_root)/xsd/makefile)
diff --git a/examples/cxx/tree/custom/mixed/people-custom.cxx b/examples/cxx/tree/custom/mixed/people-custom.cxx
deleted file mode 100644
index 7cd1947..0000000
--- a/examples/cxx/tree/custom/mixed/people-custom.cxx
+++ /dev/null
@@ -1,89 +0,0 @@
-// file : examples/cxx/tree/custom/mixed/people-custom.cxx
-// copyright : not copyrighted - public domain
-
-#include <ostream>
-
-// Include people.hxx instead of people-custom.hxx here.
-//
-#include "people.hxx"
-
-namespace people
-{
- using namespace xercesc;
-
- const XMLCh ls[] = {chLatin_L, chLatin_S, chNull};
-
- bio::
- bio ()
- : xhtml_ (0)
- {
- DOMImplementation* impl (
- DOMImplementationRegistry::getDOMImplementation (ls));
-
- doc_.reset (impl->createDocument ());
- }
-
- bio::
- bio (const DOMElement& e,
- xml_schema::flags f,
- xml_schema::container* c)
- : bio_base (e, f, c), xhtml_ (0)
- {
- DOMImplementation* impl (
- DOMImplementationRegistry::getDOMImplementation (ls));
-
- doc_.reset (impl->createDocument ());
-
- // Copy the xhtml element. Assume the first child element in
- // e is always xhtml.
- //
- for (DOMNode* n (e.getFirstChild ()); n != 0; n = n->getNextSibling ())
- {
- if (n->getNodeType () == DOMNode::ELEMENT_NODE)
- {
- xhtml_ = static_cast<DOMElement*> (doc_->importNode (n, true));
- break;
- }
- }
- }
-
- bio::
- bio (const bio& d,
- xml_schema::flags f,
- xml_schema::container* c)
- : bio_base (d, f, c), xhtml_ (0)
- {
- DOMImplementation* impl (
- DOMImplementationRegistry::getDOMImplementation (ls));
-
- doc_.reset (impl->createDocument ());
-
- xhtml_ = static_cast<DOMElement*> (
- doc_->importNode (const_cast<DOMElement*> (d.xhtml_), true));
- }
-
- bio* bio::
- _clone (xml_schema::flags f, xml_schema::container* c) const
- {
- return new bio (*this, f, c);
- }
-
- void
- operator<< (DOMElement& e, const bio& x)
- {
- // Allow our base to serialize first.
- //
- const bio_base& b (x);
- e << b;
-
- // Copy the XHTML fragment if we have one.
- //
- const DOMElement* xhtml (x.xhtml ());
-
- if (xhtml != 0)
- {
- DOMDocument* doc (e.getOwnerDocument ());
- e.appendChild (doc->importNode (const_cast<DOMElement*> (xhtml), true));
- }
- }
-}
diff --git a/examples/cxx/tree/custom/mixed/people-custom.hxx b/examples/cxx/tree/custom/mixed/people-custom.hxx
deleted file mode 100644
index 54dfb21..0000000
--- a/examples/cxx/tree/custom/mixed/people-custom.hxx
+++ /dev/null
@@ -1,83 +0,0 @@
-// file : examples/cxx/tree/custom/mixed/people-custom.hxx
-// copyright : not copyrighted - public domain
-
-// Do not include this file directly, use people.hxx instead. This
-// file is included into generated people.hxx so we do not need to
-// guard against multiple inclusions.
-//
-
-#include <cassert>
-#include <xercesc/dom/DOM.hpp>
-
-namespace people
-{
- class bio: public bio_base
- {
- // Standard constructors.
- //
- public:
- bio ();
-
- bio (const xercesc::DOMElement&,
- xml_schema::flags = 0,
- xml_schema::container* = 0);
-
- bio (const bio&,
- xml_schema::flags = 0,
- xml_schema::container* = 0);
-
- virtual bio*
- _clone (xml_schema::flags = 0,
- xml_schema::container* = 0) const;
-
- // XHTML bio as a DOM document.
- //
- public:
- const xercesc::DOMElement*
- xhtml () const
- {
- return xhtml_;
- }
-
- xercesc::DOMElement*
- xhtml ()
- {
- return xhtml_;
- }
-
- // The element should belong to the DOMDocument returned by
- // the dom_document() functions.
- //
- void
- xhtml (xercesc::DOMElement* e)
- {
- assert (e->getOwnerDocument () == doc_.get ());
-
- if (xhtml_ != 0)
- xhtml_->release ();
-
- xhtml_ = e;
- }
-
- const xercesc::DOMDocument&
- dom_document () const
- {
- return *doc_;
- }
-
- xercesc::DOMDocument&
- dom_document ()
- {
- return *doc_;
- }
-
- private:
- xercesc::DOMElement* xhtml_;
- xml_schema::dom::auto_ptr<xercesc::DOMDocument> doc_;
- };
-
- // Serialization operator.
- //
- void
- operator<< (xercesc::DOMElement&, const bio&);
-}
diff --git a/examples/cxx/tree/custom/mixed/people.xml b/examples/cxx/tree/custom/mixed/people.xml
deleted file mode 100644
index 47e68b9..0000000
--- a/examples/cxx/tree/custom/mixed/people.xml
+++ /dev/null
@@ -1,38 +0,0 @@
-<?xml version="1.0"?>
-
-<!--
-
-file : examples/cxx/tree/custom/mixed/people.xml
-copyright : not copyrighted - public domain
-
--->
-
-<ppl:directory xmlns:ppl="http://www.codesynthesis.com/people"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.codesynthesis.com/people people.xsd">
-
- <person>
- <first-name>John</first-name>
- <last-name>Doe</last-name>
- <gender>male</gender>
- <age>32</age>
- <bio>
- <xhtml xmlns="http://www.w3.org/1999/xhtml">
- <p>Married to Jane Doe.</p>
- </xhtml>
- </bio>
- </person>
-
- <person>
- <first-name>Jane</first-name>
- <last-name>Doe</last-name>
- <gender>female</gender>
- <age>28</age>
- <bio>
- <xhtml xmlns="http://www.w3.org/1999/xhtml">
- <p>Married to John Doe.</p>
- </xhtml>
- </bio>
- </person>
-
-</ppl:directory>
diff --git a/examples/cxx/tree/custom/mixed/people.xsd b/examples/cxx/tree/custom/mixed/people.xsd
deleted file mode 100644
index 03e6c97..0000000
--- a/examples/cxx/tree/custom/mixed/people.xsd
+++ /dev/null
@@ -1,45 +0,0 @@
-<?xml version="1.0"?>
-
-<!--
-
-file : examples/cxx/tree/custom/mixed/people.xsd
-copyright : not copyrighted - public domain
-
--->
-
-<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
- xmlns:ppl="http://www.codesynthesis.com/people"
- targetNamespace="http://www.codesynthesis.com/people">
-
- <xsd:simpleType name="gender">
- <xsd:restriction base="xsd:string">
- <xsd:enumeration value="male"/>
- <xsd:enumeration value="female"/>
- </xsd:restriction>
- </xsd:simpleType>
-
- <xsd:complexType name="bio" mixed="true">
- <xsd:sequence minOccurs="0" maxOccurs="unbounded">
- <xsd:any namespace="http://www.w3.org/1999/xhtml" processContents="skip"/>
- </xsd:sequence>
- </xsd:complexType>
-
- <xsd:complexType name="person">
- <xsd:sequence>
- <xsd:element name="first-name" type="xsd:string"/>
- <xsd:element name="last-name" type="xsd:string"/>
- <xsd:element name="gender" type="ppl:gender"/>
- <xsd:element name="age" type="xsd:unsignedShort"/>
- <xsd:element name="bio" type="ppl:bio"/>
- </xsd:sequence>
- </xsd:complexType>
-
- <xsd:complexType name="directory">
- <xsd:sequence>
- <xsd:element name="person" type="ppl:person" maxOccurs="unbounded"/>
- </xsd:sequence>
- </xsd:complexType>
-
- <xsd:element name="directory" type="ppl:directory"/>
-
-</xsd:schema>