summaryrefslogtreecommitdiff
path: root/xsd-examples/cxx/tree/custom/mixed/README
blob: 8f7bd13d0c62912eb04e362ce8d18e3d79352308 (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
This example shows how to use type customization to parse and serialize
mixed content. The example achieves this by customizing the type with
the mixed content model to include a DOM document that stores the data
as a raw XML representation. The customized type also provides its own
parsing constructor and serialization operator where the mixed content
is extracted from and inserted back to DOM, respectively. The use of
DOM for mixed content storage is one of the options. You may find other
data structures (e.g., a string) more suitable depending on your situation.

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 person record vocabulary. Each
  record includes the bio element which represents arbitrary XHTML
  fragments as mixed content.

people.xml
  Sample XML instance document.

people.hxx
people.ixx
people.cxx
  C++ types that represent the given 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 files are generated by the XSD compiler from people.xsd using the
  following command line:

  xsd cxx-tree --generate-serialization --custom-type bio=/bio_base \
      --hxx-epilogue '#include "people-custom.hxx"' people.xsd

  The --custom-type option is used to customize the bio type.

people-custom.hxx
  Header file which defines our own bio class by inheriting from the
  generated bio_base. It is included at the end of people.hxx using
  the --hxx-epilogue option.

people-custom.cxx
  Source file which contains the implementation of our bio 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 data to STDERR, including the bio information converted to text.
  Finally, the driver serializes the object model back to XML.

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 people.cxx
c++ -DXSD_CXX11 -c people-custom.cxx
c++ -DXSD_CXX11 -c driver.cxx
c++ -o driver driver.o people.o people-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 people.xml