From f0510d2f90467de8e8f260b47d79a9baaf9bef17 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 17 Sep 2009 07:15:29 +0200 Subject: Start tracking XSD with git --- examples/cxx/tree/hello/README | 26 ++++++++++++++ examples/cxx/tree/hello/driver.cxx | 37 ++++++++++++++++++++ examples/cxx/tree/hello/hello.xml | 20 +++++++++++ examples/cxx/tree/hello/hello.xsd | 53 ++++++++++++++++++++++++++++ examples/cxx/tree/hello/makefile | 71 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 207 insertions(+) create mode 100644 examples/cxx/tree/hello/README create mode 100644 examples/cxx/tree/hello/driver.cxx create mode 100644 examples/cxx/tree/hello/hello.xml create mode 100644 examples/cxx/tree/hello/hello.xsd create mode 100644 examples/cxx/tree/hello/makefile (limited to 'examples/cxx/tree/hello') diff --git a/examples/cxx/tree/hello/README b/examples/cxx/tree/hello/README new file mode 100644 index 0000000..bb98584 --- /dev/null +++ b/examples/cxx/tree/hello/README @@ -0,0 +1,26 @@ +This is a "Hello, world!" example that shows how to use the C++/Tree +mapping to access XML instance documents described by XML Schema +definitions. + +The example consists of the following files: + +hello.xsd + XML Schema which describes "hello" instance documents. + +hello.xml + Sample XML instance document. + +hello.hxx +hello.cxx + C++ types that represent the given vocabulary and a set of parsing + functions that convert XML instance documents to a tree-like in-memory + object model. These are generated by XSD from hello.xsd. + +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 content of the object model to STDERR. + +To run the example on the sample XML instance document simply execute: + +$ ./driver hello.xml diff --git a/examples/cxx/tree/hello/driver.cxx b/examples/cxx/tree/hello/driver.cxx new file mode 100644 index 0000000..6ea6823 --- /dev/null +++ b/examples/cxx/tree/hello/driver.cxx @@ -0,0 +1,37 @@ +// file : examples/cxx/tree/hello/driver.cxx +// author : Boris Kolpackov +// copyright : not copyrighted - public domain + +#include // std::auto_ptr +#include + +#include "hello.hxx" + +using namespace std; + +int +main (int argc, char* argv[]) +{ + if (argc != 2) + { + cerr << "usage: " << argv[0] << " hello.xml" << endl; + return 1; + } + + try + { + auto_ptr h (hello (argv[1])); + + for (hello_t::name_const_iterator i (h->name ().begin ()); + i != h->name ().end (); + ++i) + { + cout << h->greeting () << ", " << *i << "!" << endl; + } + } + catch (const xml_schema::exception& e) + { + cerr << e << endl; + return 1; + } +} diff --git a/examples/cxx/tree/hello/hello.xml b/examples/cxx/tree/hello/hello.xml new file mode 100644 index 0000000..bcde610 --- /dev/null +++ b/examples/cxx/tree/hello/hello.xml @@ -0,0 +1,20 @@ + + + + + + + Hello + + sun + moon + world + + diff --git a/examples/cxx/tree/hello/hello.xsd b/examples/cxx/tree/hello/hello.xsd new file mode 100644 index 0000000..e8f5147 --- /dev/null +++ b/examples/cxx/tree/hello/hello.xsd @@ -0,0 +1,53 @@ + + + + + + + + + + + The hello_t type consists of a greeting phrase and a + collection of names to which this greeting applies. + + + + + + + + + The greeting element contains the greeting phrase + for this hello object. + + + + + + + + The name elements contains names to be greeted. + + + + + + + + + + + The hello element is a root of the Hello XML vocabulary. + Every conforming document should start with this element. + + + + + diff --git a/examples/cxx/tree/hello/makefile b/examples/cxx/tree/hello/makefile new file mode 100644 index 0000000..95288f5 --- /dev/null +++ b/examples/cxx/tree/hello/makefile @@ -0,0 +1,71 @@ +# file : examples/cxx/tree/hello/makefile +# author : Boris Kolpackov +# 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 := hello.xsd +cxx := driver.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 := + +$(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) -- cgit v1.1