blob: 39f9c091ad8cab3c032277e22de5962eb2bd4737 (
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
|
This example shows how to use the C++/Tree mapping together with XPath.
In particular, it shows how to execute an XPath query on the underlying
DOM document and then handle the result using the more convenient object
model representation. For more information on maintaining association
with the underlying DOM document, refer to Section 5.1, "DOM Association"
in the C++/Tree Mapping User Manual.
You will need the XQilla library[1] which provides XQuery and XPath 2
support on top of Xerces-C++ in order to build and run this example.
[1] http://xqilla.sourceforge.net
The example consists of the following files:
people.xsd
XML Schema definition for a simple person record vocabulary.
people.xml
Sample XML instance document.
people.hxx
people.cxx
C++ types that represent the person record 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 people.xsd
dom-parse.hxx
dom-parse.cxx
Definition and implementation of the parse() function that parses an
XML document to a DOM document.
driver.cxx
Driver for the example. It first calls the above parse() function to
parse the input file to a DOM document using XQilla-provided DOM
Implementation with support for XPath 2. It then parses the DOM
document to the object model. Finally, it prepares and executes
an XPath query on the underlying DOM document and then handles
the result by getting back from the returned DOM nodes to object
model nodes.
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 dom-parse.cxx
c++ -DXSD_CXX11 -c driver.cxx
c++ -o driver driver.o people.o dom-parse.o -lxqilla -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 document execute:
./driver people.xml
|