blob: 3296508ef96544b68bae05083bf9e5677a5b6525 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
This example shows how to map user-defined XML Schema types to custom C++
classes. It presents the complex case where the customized types are
inherited from in the same schema. For the simple case see the contacts
example. 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 people database.
people.xml
Sample XML instance document.
people-fwd.hxx
people.hxx
people.ixx
people.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 files are generated by the XSD compiler from people.xsd using the
following command line:
xsd cxx-tree --generate-forward --generate-polymorphic \
--polymorphic-type person \
--custom-type "person=person_impl<person_base>/person_base" \
--custom-type "superman=superman_impl<superman_base>/superman_base" \
--custom-type "batman=batman_impl<batman_base>/batman_base" \
--fwd-prologue '#include "people-custom-fwd.hxx"' \
--hxx-prologue '#include "people-custom.hxx"' people.xsd
The --custom-type option is used to customize the person, superman, and
batman types. Generation of the people-fwd.hxx forward declaration
file is requested with the --generate-forward option. Note also that
we use the --generate-polymorphic command line option as well as
--polymorphic-type to mark the type hierarchy starting with the
person type as polymorphic.
people-custom-fwd.hxx
Header file which forward-declares our own person, superman, and batman
as class templates. It is included at the beginning of people-fwd.hxx
using the --fwd-prologue option.
people-custom.hxx
Header file which defines our own person, superman, and batman class
templates by inheriting from the generated person_base, superman_base,
and batman_base. It is included at the beginning of people.hxx using
the --hxx-prologue option.
people-custom.cxx
Source file which contains the implementations and instantiations of
our person, superman, and batman class templates.
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 database to STDERR.
To compile and link the example manually from the command line we can use
the following commands (replace 'c++' with your C++ compiler name):
c++ -c people.cxx
c++ -c people-custom.cxx
c++ -c driver.cxx
c++ -o driver driver.o people.o people-custom.o -lxerces-c
To run the example on the sample XML instance document execute:
./driver people.xml
|