summaryrefslogtreecommitdiff
path: root/examples/cxx/tree/custom/comments
diff options
context:
space:
mode:
Diffstat (limited to 'examples/cxx/tree/custom/comments')
-rw-r--r--examples/cxx/tree/custom/comments/README57
-rw-r--r--examples/cxx/tree/custom/comments/dom-parse.cxx93
-rw-r--r--examples/cxx/tree/custom/comments/dom-parse.hxx22
-rw-r--r--examples/cxx/tree/custom/comments/driver.cxx90
-rw-r--r--examples/cxx/tree/custom/comments/makefile122
-rw-r--r--examples/cxx/tree/custom/comments/people.xml20
-rw-r--r--examples/cxx/tree/custom/comments/people.xsd29
-rw-r--r--examples/cxx/tree/custom/comments/xml-schema-custom.cxx117
-rw-r--r--examples/cxx/tree/custom/comments/xml-schema-custom.hxx57
9 files changed, 0 insertions, 607 deletions
diff --git a/examples/cxx/tree/custom/comments/README b/examples/cxx/tree/custom/comments/README
deleted file mode 100644
index 8fd69d0..0000000
--- a/examples/cxx/tree/custom/comments/README
+++ /dev/null
@@ -1,57 +0,0 @@
-This example shows how to customize the anyType XML Schema built-in
-type to implement preservation of comments stored in XML documents.
-Because anyType is a base type for every generated type, you can use
-this technique to implement custom functionality that spans the
-entire type system. For more information on the C++/Tree mapping
-customization see the C++/Tree Mapping Customization Guide[2].
-
-[2] 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.
-
-people.xml
- Sample XML instance document.
-
-xml-schema.hxx
- C++ types for XML Schema built-in types. This header file is generated
- by XSD using the --generate-xml-schema option. The --custom-type option
- is also used to customize the xsd:anyType type.
-
-people.hxx
-people.ixx
-people.cxx
- C++ types that represent the person record 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 --extern-xml-schema option in order to
- include xml-schema.hxx.
-
-xml-schema-custom.hxx
- Header file which defines our own xml_schema::type class. It is
- included at the end of xml-schema.hxx using the --hxx-epilogue
- option.
-
-xml-schema-custom.cxx
- Source file which contains the implementation of our xml_schema:type
- class.
-
-dom-parse.hxx
-dom-parse.cxx
- Definition and implementation of the parse() function that
- parses an XML document to a DOM document while preserving
- XML comments.
-
-driver.cxx
- Driver for the example. It first calls the above parse() function
- to parse the input file to a DOM document. It then parses the DOM
- document to the object model and performs a number of modifications
- on this object model. Finally, it serializes the modified object
- model back to XML, including XML comments.
-
-To run the example on the sample XML instance document simply execute:
-
-$ ./driver people.xml
diff --git a/examples/cxx/tree/custom/comments/dom-parse.cxx b/examples/cxx/tree/custom/comments/dom-parse.cxx
deleted file mode 100644
index 9999f67..0000000
--- a/examples/cxx/tree/custom/comments/dom-parse.cxx
+++ /dev/null
@@ -1,93 +0,0 @@
-// file : examples/cxx/tree/custom/comments/dom-parse.cxx
-// 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));
-
- xml::dom::auto_ptr<DOMLSParser> parser (
- impl->createLSParser (DOMImplementationLS::MODE_SYNCHRONOUS, 0));
-
- DOMConfiguration* conf (parser->getDomConfig ());
-
- // Preserve comment nodes in the document.
- //
- conf->setParameter (XMLUni::fgDOMComments, true);
-
- // 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);
-
- // Xerces-C++ 3.1.0 is the first version with working multi import
- // support.
- //
-#if _XERCES_VERSION >= 30100
- conf->setParameter (XMLUni::fgXercesHandleMultipleImports, true);
-#endif
-
- // 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);
-
- // Prepare input stream.
- //
- xml::sax::std_input_source isrc (is, id);
- Wrapper4InputSource wrap (&isrc, false);
-
- xml::dom::auto_ptr<DOMDocument> doc (parser->parse (&wrap));
-
- eh.throw_if_failed<tree::parsing<char> > ();
-
- return doc;
-}
diff --git a/examples/cxx/tree/custom/comments/dom-parse.hxx b/examples/cxx/tree/custom/comments/dom-parse.hxx
deleted file mode 100644
index fea46d0..0000000
--- a/examples/cxx/tree/custom/comments/dom-parse.hxx
+++ /dev/null
@@ -1,22 +0,0 @@
-// file : examples/cxx/tree/custom/comments/dom-parse.hxx
-// 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/custom/comments/driver.cxx b/examples/cxx/tree/custom/comments/driver.cxx
deleted file mode 100644
index 39b16f7..0000000
--- a/examples/cxx/tree/custom/comments/driver.cxx
+++ /dev/null
@@ -1,90 +0,0 @@
-// file : examples/cxx/tree/custom/commens/driver.cxx
-// copyright : not copyrighted - public domain
-
-#include <memory> // std::auto_ptr
-#include <fstream>
-#include <iostream>
-
-#include <xercesc/dom/DOMDocument.hpp>
-#include <xercesc/util/PlatformUtils.hpp>
-
-#include "people.hxx"
-#include "dom-parse.hxx"
-
-using namespace std;
-
-int
-main (int argc, char* argv[])
-{
- if (argc != 2)
- {
- cerr << "usage: " << argv[0] << " people.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 (see below).
- //
- xercesc::XMLPlatformUtils::Initialize ();
-
- try
- {
- using namespace people;
- namespace xml = xsd::cxx::xml;
-
- ifstream ifs;
- ifs.exceptions (ifstream::badbit | ifstream::failbit);
- ifs.open (argv[1]);
-
- // For performance reasons the internal XML to DOM parsing code
- // discards comments in the resulting DOM document. To overcome
- // this we are going to use our own parse() function from
- // dom-parse.hxx that preserves comments in the resulting DOM
- // documents.
- //
- xml_schema::dom::auto_ptr<xercesc::DOMDocument> doc (
- parse (ifs, argv[1], true));
-
- // Parse the DOM document to the object model.
- //
- std::auto_ptr<catalog> c (catalog_ (*doc));
-
- // Change the object model.
- //
- catalog::person_sequence& ps (c->person ());
-
- for (catalog::person_iterator i (ps.begin ()); i != ps.end (); ++i)
- {
- i->age (i->age () + 1);
- }
-
- person john ("John Doe", 30);
- john.comment ("Record for John Doe");
-
- ps.push_back (john);
-
- // Serialize.
- //
- xml_schema::namespace_infomap map;
-
- map["ppl"].name = "http://www.codesynthesis.com/people";
- map["ppl"].schema = "people.xsd";
-
- catalog_ (std::cout, *c, map);
- }
- 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;
- }
-
- xercesc::XMLPlatformUtils::Terminate ();
- return r;
-}
diff --git a/examples/cxx/tree/custom/comments/makefile b/examples/cxx/tree/custom/comments/makefile
deleted file mode 100644
index 478ab05..0000000
--- a/examples/cxx/tree/custom/comments/makefile
+++ /dev/null
@@ -1,122 +0,0 @@
-# file : examples/cxx/tree/custom/comments/makefile
-# license : GNU GPL v2 + exceptions; see accompanying LICENSE file
-
-include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../build/bootstrap.make
-
-xsd := people.xsd
-cxx := driver.cxx xml-schema-custom.cxx dom-parse.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)
-
-# Header file for XML Schema namespace.
-#
-$(out_base)/xml-schema.hxx: $(out_root)/xsd/xsd
- $(call message,xsd $(src_base)/xml-schema.xsd,\
-$(out_root)/xsd/xsd cxx-tree --output-dir $(out_base) --generate-xml-schema \
---generate-serialization --custom-type anyType=/type_base \
---hxx-epilogue '#include "xml-schema-custom.hxx"' xml-schema.xsd)
-
-#
-#
-genf := $(xsd:.xsd=.hxx) $(xsd:.xsd=.ixx) $(xsd:.xsd=.cxx)
-gen := $(addprefix $(out_base)/,$(genf))
-
-$(gen): xsd := $(out_root)/xsd/xsd
-$(gen): xsd_options += \
---generate-inline \
---generate-serialization \
---extern-xml-schema xml-schema.xsd
-
-$(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)/xml-schema-custom.hxx,$(install_doc_dir)/xsd/$(path)/xml-schema-custom.hxx)
- $(call install-data,$(src_base)/xml-schema-custom.cxx,$(install_doc_dir)/xsd/$(path)/xml-schema-custom.cxx)
- $(call install-data,$(src_base)/dom-parse.hxx,$(install_doc_dir)/xsd/$(path)/dom-parse.hxx)
- $(call install-data,$(src_base)/dom-parse.cxx,$(install_doc_dir)/xsd/$(path)/dom-parse.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)/xml-schema-custom.hxx,$(dist_prefix)/$(path)/xml-schema-custom.hxx)
- $(call install-data,$(src_base)/xml-schema-custom.cxx,$(dist_prefix)/$(path)/xml-schema-custom.cxx)
- $(call install-data,$(src_base)/dom-parse.hxx,$(dist_prefix)/$(path)/dom-parse.hxx)
- $(call install-data,$(src_base)/dom-parse.cxx,$(dist_prefix)/$(path)/dom-parse.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))
- $(call message,rm $$1,rm -f $$1,$(out_base)/xml-schema.hxx)
-
-# Generated .gitignore.
-#
-ifeq ($(out_base),$(src_base))
-$(gen): | $(out_base)/.gitignore
-$(driver): | $(out_base)/.gitignore
-
-$(out_base)/.gitignore: files := driver xml-schema.hxx $(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/comments/people.xml b/examples/cxx/tree/custom/comments/people.xml
deleted file mode 100644
index 55c08a1..0000000
--- a/examples/cxx/tree/custom/comments/people.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-<?xml version="1.0"?>
-
-<!--
-
-file : examples/cxx/tree/custom/comments/people.xml
-copyright : not copyrighted - public domain
-
--->
-
-<ppl:catalog 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>
- <!--Record for Joe Dirt-->
- <name>Joe Dirt</name>
- <age>28</age>
- </person>
-
-</ppl:catalog>
diff --git a/examples/cxx/tree/custom/comments/people.xsd b/examples/cxx/tree/custom/comments/people.xsd
deleted file mode 100644
index e70dd2a..0000000
--- a/examples/cxx/tree/custom/comments/people.xsd
+++ /dev/null
@@ -1,29 +0,0 @@
-<?xml version="1.0"?>
-
-<!--
-
-file : examples/cxx/tree/custom/comments/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:complexType name="person">
- <xsd:sequence>
- <xsd:element name="name" type="xsd:string"/>
- <xsd:element name="age" type="xsd:unsignedShort"/>
- </xsd:sequence>
- </xsd:complexType>
-
- <xsd:complexType name="catalog">
- <xsd:sequence>
- <xsd:element name="person" type="ppl:person" maxOccurs="unbounded"/>
- </xsd:sequence>
- </xsd:complexType>
-
- <xsd:element name="catalog" type="ppl:catalog"/>
-
-</xsd:schema>
diff --git a/examples/cxx/tree/custom/comments/xml-schema-custom.cxx b/examples/cxx/tree/custom/comments/xml-schema-custom.cxx
deleted file mode 100644
index 67937d1..0000000
--- a/examples/cxx/tree/custom/comments/xml-schema-custom.cxx
+++ /dev/null
@@ -1,117 +0,0 @@
-// file : examples/cxx/tree/custom/comments/xml-schema-custom.cxx
-// copyright : not copyrighted - public domain
-
-// Include xml-schema.hxx instead of xml-schema-custom.hxx here.
-//
-#include "xml-schema.hxx"
-
-#include <xercesc/dom/DOMComment.hpp>
-#include <xercesc/dom/DOMDocument.hpp>
-
-#include <xsd/cxx/xml/string.hxx> // xml::transcode, xml::string
-
-namespace xml = xsd::cxx::xml;
-
-namespace xml_schema
-{
- type::
- type ()
- : type_base ()
- {
- }
-
- type::
- type (const xercesc::DOMElement& e, flags f, container* c)
- : type_base (e, f, c)
- {
- using namespace xercesc;
-
- // Here we are only handling a comment that is the first
- // node in the element's content.
- //
- const DOMNode* n (e.getFirstChild ());
-
- if (n != 0 && n->getNodeType () == DOMNode::COMMENT_NODE)
- {
- const DOMComment* c (static_cast<const DOMComment*> (n));
- comment_ = xml::transcode<char> (c->getData ());
- }
- }
-
- type::
- type (const xercesc::DOMAttr& a, flags f, container* c)
- : type_base (a, f, c)
- {
- // No comments for attributes.
- //
- }
-
- type::
- type (const std::string& s, const xercesc::DOMElement* e,
- flags f, container* c)
- : type_base (s, e, f, c)
- {
- // No comments for list items.
- //
- }
-
- type::
- type (const type& x, flags f, container* c)
- : type_base (x, f, c), comment_ (x.comment_)
- {
- }
-
- type* type::
- _clone (flags f, container* c) const
- {
- return new type (*this, f, c);
- }
-
- // Serialization operators.
- //
- void
- operator<< (xercesc::DOMElement& e, const type& x)
- {
- // Call our base first.
- //
- const type_base& b (x);
- e << b;
-
- // Add the comment if any.
- //
- const std::string s (x.comment ());
-
- if (!s.empty ())
- {
- using namespace xercesc;
-
- DOMDocument* doc (e.getOwnerDocument ());
- DOMComment* c (doc->createComment (xml::string (s).c_str ()));
- e.appendChild (c);
- }
- }
-
- void
- operator<< (xercesc::DOMAttr& a, const type& x)
- {
- // Call our base first.
- //
- const type_base& b (x);
- a << b;
-
- // No comments for attributes.
- //
- }
-
- void
- operator<< (xml_schema::list_stream& ls, const type& x)
- {
- // Call our base first.
- //
- const type_base& b (x);
- ls << b;
-
- // No comments for list items.
- //
- }
-}
diff --git a/examples/cxx/tree/custom/comments/xml-schema-custom.hxx b/examples/cxx/tree/custom/comments/xml-schema-custom.hxx
deleted file mode 100644
index 0442a44..0000000
--- a/examples/cxx/tree/custom/comments/xml-schema-custom.hxx
+++ /dev/null
@@ -1,57 +0,0 @@
-// file : examples/cxx/tree/custom/comments/xml-schema-custom.hxx
-// copyright : not copyrighted - public domain
-
-// Do not include this file directly, use xml-schema.hxx instead. This
-// file is included into generated xml-schema.hxx so we do not need to
-// guard against multiple inclusions.
-//
-
-#include <string>
-
-namespace xml_schema
-{
- // When customizing anyType always inherit from the original type.
- //
- class type: public type_base
- {
- public:
- type ();
- type (const xercesc::DOMElement&, flags = 0, container* = 0);
- type (const xercesc::DOMAttr&, flags = 0, container* = 0);
- type (const std::string&, const xercesc::DOMElement*,
- flags = 0, container* = 0);
- type (const type&, flags = 0, container* = 0);
-
- virtual type*
- _clone (flags = 0, container* = 0) const;
-
- public:
- // Comment manipulation API.
- //
- const std::string&
- comment () const
- {
- return comment_;
- }
-
- void
- comment (const std::string& c)
- {
- comment_ = c;
- }
-
- private:
- std::string comment_;
- };
-
- // New serialization operators.
- //
- void
- operator<< (xercesc::DOMElement&, const type&);
-
- void
- operator<< (xercesc::DOMAttr&, const type&);
-
- void
- operator<< (xml_schema::list_stream&, const type&);
-}