blob: bd6d0c9137f0f1929d82c217f722076a3bfd2c50 (
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
|
This example shows how to use ordered types to capture and maintain
element order, including element wildcards.
The example consists of the following files:
transactions.xsd
XML Schema which describes various bank transactions. A batch of
transactions can contain any number of different transactions in
any order but the order of transaction in the batch is significant.
transactions.xml
Sample XML instance document.
transactions.hxx
transactions.cxx
C++ types that represent the given vocabulary as well as a set of
parsing and serialization functions.
These files are generated by the XSD compiler from transactions.xsd
using the following command line:
xsd cxx-tree --generate-serialization --generate-wildcard \
--ordered-type batch transactions.xsd
Note that the --ordered-type option is used to indicate to the XSD
compiler that the batch type is ordered. We also use the
--generate-wildcard option to enable wildcard support. An element
wildcard is used in the batch to allow transaction extensions.
driver.cxx
Driver for the example. It first calls one of the parsing functions
that constructs the object model from the input XML file. It then
iterates over transactions in the batch using the content order
sequence. The driver then performs various modifications of the
object model while showing how to maintain the content order.
Finally, it saves the modified transaction batch back to XML to
verify that the content order is preserved in the output document.
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 transactions.cxx
c++ -DXSD_CXX11 -c driver.cxx
c++ -o driver driver.o transactions.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 transactions.xml
|