blob: a4297ba6b6ab83a7623ef28fd604b7fc2851e769 (
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
|
This example shows how to customize the XML Schema built-in types by mapping
xsd:date built-in type to the date class from the Boost date_time library.
You will need the Boost date_time library[1] installed in order to build
and run this example. For more information on the C++/Tree mapping
customization see the C++/Tree Mapping Customization Guide[2].
[1] http://www.boost.org
[2] http://wiki.codesynthesis.com/Tree/Customization_guide
The example consists of the following files:
calendar.xsd
XML Schema definition for a simple calendar format.
calendar.xml
Sample XML instance document.
xml-schema.hxx
C++ types for XML Schema built-in types.
This header file is generated by the XSD compiler in the
--generate-xml-schema mode using the following command line:
xsd cxx-tree --generate-xml-schema --custom-type date \
--hxx-epilogue '#include "xml-schema-custom.hxx"' xml-schema.xsd
The --custom-type option is used to customize the xsd:date type.
calendar.hxx
calendar.ixx
calendar.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 calendar.xsd using the
following command line:
xsd cxx-tree --extern-xml-schema xml-schema.xsd calendar.xsd
The --extern-xml-schema option is used to include xml-schema.hxx.
xml-schema-custom.hxx
Header file which defines our own xml_schema::date 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:date
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 calendar events 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++ -DXSD_CXX11 -c calendar.cxx
c++ -DXSD_CXX11 -c xml-schema-custom.cxx
c++ -DXSD_CXX11 -c driver.cxx
c++ -o driver driver.o calendar.o xml-schema-custom.o -lxerces-c
Note that we need to define the XSD_CXX11 preprocessor macro since the
source code includes libxsd headers directly.
To run the example on the sample XML instance document execute:
./driver calendar.xml
|