diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2009-02-24 15:16:26 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2009-02-24 15:16:26 +0200 |
commit | 707cc94fe52463870a9c6c8e2e66eaaa389e601d (patch) | |
tree | 13e10ff28bf4455d915f9d59b401bdbb62a393cb /examples/cxx/hybrid/hello |
Start tracking XSD/e with git after version 3.0.03.0.0
Diffstat (limited to 'examples/cxx/hybrid/hello')
-rw-r--r-- | examples/cxx/hybrid/hello/README | 37 | ||||
-rw-r--r-- | examples/cxx/hybrid/hello/driver.cxx | 66 | ||||
-rw-r--r-- | examples/cxx/hybrid/hello/hello.xml | 20 | ||||
-rw-r--r-- | examples/cxx/hybrid/hello/hello.xsd | 22 | ||||
-rw-r--r-- | examples/cxx/hybrid/hello/makefile | 71 |
5 files changed, 216 insertions, 0 deletions
diff --git a/examples/cxx/hybrid/hello/README b/examples/cxx/hybrid/hello/README new file mode 100644 index 0000000..dd5a2bb --- /dev/null +++ b/examples/cxx/hybrid/hello/README @@ -0,0 +1,37 @@ +This is a "Hello, world!" example that shows how to use the Embedded +C++/Hybrid mapping to parse XML documents. + +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 + +hello-pskel.hxx +hello-pskel.cxx +hello-pimpl.hxx +hello-pimpl.cxx + Object model (the first pair of files), parser skeletons (the + second pair) and parser implementations (the third pair). These + files are generated by the XSD/e compiler from hello.xsd. The + --generate-parser and --generate-aggregate options were used + to request the generation of the parsing code. + +driver.cxx + Driver for the example. It first calls the parser that + constructs the object model from the input XML 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 + +The example reads from STDIN if input file is not specified: + +$ ./driver <hello.xml diff --git a/examples/cxx/hybrid/hello/driver.cxx b/examples/cxx/hybrid/hello/driver.cxx new file mode 100644 index 0000000..ac99149 --- /dev/null +++ b/examples/cxx/hybrid/hello/driver.cxx @@ -0,0 +1,66 @@ +// file : examples/cxx/hybrid/hello/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : not copyrighted - public domain + +#include <iostream> + +#include "hello.hxx" +#include "hello-pimpl.hxx" + +using namespace std; + +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 + { + // Parse. + // + hello_paggr hello_p; + + xml_schema::document_pimpl doc_p (hello_p.root_parser (), + hello_p.root_name ()); + hello_p.pre (); + + if (argc < 2) + doc_p.parse (cin); + else + doc_p.parse (argv[1]); + + hello* h = hello_p.post (); + + // Print what we've got. + // + for (hello::name_const_iterator i = h->name ().begin (); + i != h->name ().end (); + ++i) + { + cout << h->greeting () << ", " << *i << "!" << endl; + } + + delete h; + } + catch (const xml_schema::parser_exception& e) + { + cerr << input << ":" << e.line () << ":" << e.column () << ": " + << e.text () << endl; + return 1; + } + catch (const std::ios_base::failure&) + { + cerr << input << ": unable to open or read failure" << endl; + return 1; + } + + return 0; +} diff --git a/examples/cxx/hybrid/hello/hello.xml b/examples/cxx/hybrid/hello/hello.xml new file mode 100644 index 0000000..32e70f1 --- /dev/null +++ b/examples/cxx/hybrid/hello/hello.xml @@ -0,0 +1,20 @@ +<?xml version="1.0"?> + +<!-- + +file : examples/cxx/hybrid/hello/hello.xml +author : Boris Kolpackov <boris@codesynthesis.com> +copyright : not copyrighted - public domain + +--> + +<hello xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="hello.xsd"> + + <greeting>Hello</greeting> + + <name>sun</name> + <name>moon</name> + <name>world</name> + +</hello> diff --git a/examples/cxx/hybrid/hello/hello.xsd b/examples/cxx/hybrid/hello/hello.xsd new file mode 100644 index 0000000..66ea021 --- /dev/null +++ b/examples/cxx/hybrid/hello/hello.xsd @@ -0,0 +1,22 @@ +<?xml version="1.0"?> + +<!-- + +file : examples/cxx/hybrid/hello/hello.xsd +author : Boris Kolpackov <boris@codesynthesis.com> +copyright : not copyrighted - public domain + +--> + +<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> + + <xsd:complexType name="hello"> + <xsd:sequence> + <xsd:element name="greeting" type="xsd:string"/> + <xsd:element name="name" type="xsd:string" maxOccurs="unbounded"/> + </xsd:sequence> + </xsd:complexType> + + <xsd:element name="hello" type="hello"/> + +</xsd:schema> diff --git a/examples/cxx/hybrid/hello/makefile b/examples/cxx/hybrid/hello/makefile new file mode 100644 index 0000000..b347837 --- /dev/null +++ b/examples/cxx/hybrid/hello/makefile @@ -0,0 +1,71 @@ +# file : examples/cxx/hybrid/hello/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 := hello.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,\ +$(cxx:.cxx=.o) \ +$(xsd:.xsd=.o) \ +$(xsd:.xsd=-pskel.o) \ +$(xsd:.xsd=-pimpl.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) + +$(gen): $(out_root)/xsde/xsde +$(gen): xsde := $(out_root)/xsde/xsde +$(gen): xsde_options += --generate-parser --generate-aggregate + +$(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) |